What does `&:` mean in this Ruby snippet? [duplicate] - ruby

This question already has answers here:
What does map(&:name) mean in Ruby?
(17 answers)
Closed 12 months ago.
This is from a solution I saw at a competitive programming site:
gets.split.map &:to_i
The &:to_i phrase seems to be equivalent to {|s| s.to_i}, but I can't find anything about that syntax at ruby-doc.org, or a match for "&:" [ruby] here. (I don't know what to call it for an English language search, either.)
If it matters, that site is using Ruby 3.0.1.

It's an example of Symbol#to_proc - see https://www.brianstorti.com/understanding-ruby-idiom-map-with-symbol/ for a more detailed explanation, or the ruby API documentation

Related

JSTL solution for providing space between capital letters [duplicate]

This question already has answers here:
How to call a static method in JSP/EL?
(9 answers)
Closed 5 years ago.
Is there any way to provide space between Capital Letters.
Eg. I have a jstl expression ${platName} which outputs AmazonEcho
What I need as output is Amazon Echo.
I tried a few jstl functions but it didn`t help.
Thanks, this worked
${platName.replaceAll("(\\p{Ll})(\\p{Lu})","$1 $2")}

Connect prolog code with C# program [duplicate]

This question already has answers here:
Integrating Prolog with C# [closed]
(7 answers)
Closed 8 years ago.
I have a prolog code for searching a book. It is a simple game. I want to make interfaces with C#. But i don't know how to connect prolog into c#. Please help me. How to conncet prolog with C#.
Besides the answers mentioned on the comment link there is also a SWI Prolog has a C# Interface. You can see it here.
Here is an example provided by the aforementioned link:
PlQuery q = new PlQuery("member(A, [a,b,c])");
foreach (PlTermV s in q.Solutions)
Console.WriteLine(s[0].ToString());
There is a full documentation.

In CoffeeScript, what is the existential operator for and how do you use it? [duplicate]

This question already has an answer here:
How does CoffeeScript's existential operator work?
(1 answer)
Closed 9 years ago.
I see all sorts of questions about the existential operator on SO, but none of them ask the fundamental question of "what is it for" and "how do you use it?" so I thought I'd ask this here.
The answer here would probably suffice as an answer to this question, but the problem is the question title doesn't suggest that. As a result, it's very hard to find this question by a google search. So, my intention here is to make it easier to learn what this operator does from a google search.
BTW, I am aware of the section in the The Little Book on CoffeeScript titled "Aliases & the Existential Operator", but for some reason I don't like its explanation. It doesn't make me feel like "I get it".
The existential operator provides a more concise and expressive way to handle null and undefined properties.
Instead of
if (user && user.url && user.url.indexOf('foo'))
you can do
if user?.url?.indexOf 'foo'
Instead of
if (baker.bakeBread) { baker.bakeBread()}
you can do coffeescript
baker.bakeBread?()

Can I reflect all the methods of a class in Ruby [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Get list of a class' methods
Suppose I haven't any reference on hand, and I want to see all the methods in the built-in File class, is that simply available?
---------------------------EDIT---------------------------
answered in Get list of a class' instance methods
Sure, try:
File.methods
And if you have the awesome_print gem installed then it formats the list nicely and provides extra information.

Ruby syntax question [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicates:
Double colons rails
What does :: do?
I was reading a manual on Rails and came across this snippet:
match 'rocketeer.js' => ::TestRoutingMapper::RocketeerApp
I'd never seen the :: syntax at the head of a class name before. I'm wondering what is the significance of writing it this way.
See my answer to What does :: do?

Resources