What does ? do in this Ruby expression? [duplicate] - ruby

This question already has answers here:
What are the restrictions for method names in Ruby?
(5 answers)
Closed 7 years ago.
On the Chef Style Guide page appears this Ruby expression:
antarctica_hint = hint?('antarctica')
What exactly does the ? after hint and before ('antarctica') mean? Is it just part of the method name? (i.e. the method is called 'hint?' not 'hint')

It is part of method name, and people typically (not always) use it for methods that return boolean value.
An example from Ruby is Class#respond_to?

Related

what is 'property' in ruby programming language [duplicate]

This question already has answers here:
What's the nature of "property" in a Ruby class?
(3 answers)
Closed 7 years ago.
I have a very basic question about Ruby which I can't seem to answer from browsing online:
property :currency, String
What does 'property' above mean? What circumstances should I use it under?
As for many case in Rails, this is (most probably) a carefully disguised method call. Remember that in Ruby, parenthesis around method calls are options, so:
add(3, 4)
add 3, 4
are equivalent. So in your case,
property :currency, String
can actually be written as:
property(:currency, String)
So, a call to a method called "property" which takes two arguments, a Symbol and a Class. The method is most probably defined on a class from a library you are using.
property :currency, String is a method call. When you find a line like that in a class then that means that a method property is called with :currency and String as parameter.
For the special mean of this method, look at the docs

What does question mark in ".includes?" mean in ruby? [duplicate]

This question already has answers here:
What does the question mark at the end of a method name mean in Ruby?
(9 answers)
Closed 8 years ago.
I ran across this piece of code and was wondering what the ? means in this case? It is part of an if statement condition
if user_input.include? "s"
what does the "?" mean?
sorry, i'm new to ruby
The ? is part of the method name.
In Ruby, method names are allowed to end in a ? or an !. Typically, ? indicates a predicate (a method that returns a Boolean), and ! indicates a destructive operation (something that modifies the receiver object).

Is there a default difference between methods with '!' and without, in ruby? [duplicate]

This question already has answers here:
Why are exclamation marks used in Ruby methods?
(12 answers)
Closed 9 years ago.
Is there a default difference between methods with '!' and without, in ruby?
collect v collect!
flatten v flatten!
and so on..
In ruby the main difference is that, the ! methods are selfish, i.e. they apply the changes to the self object. They return nil, when no changes are done, while the non-! methods create new modified object.
In Rails the difference is that, the ! methods are safe versions of non-! methods, that means the ! methods raises an exception when the code encountered an error during execution, while non-! methods just return error state, usually false condition.

What is the ruby Regex or String #=== method/operator? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
=== vs. == in Ruby
I can't find verbose docs on this at all. The doc page is broken:
http://ruby-doc.org/core-1.9.3/String.html
The regex page uses the word "case" in two different senses (!) and I can't understand what the point is:
http://www.ruby-doc.org/core-1.9.3/Regexp.html#method-i-3D-3D-3D
And it was in use in Rails:
https://github.com/rails/rails/commit/3756a3fdfe8d339a53bf347487342f93fd9e1edb?utm_source=rubyweekly&utm_medium=email
=== is the "case equality" operator:
In Ruby, triple equals (Object#===) is, "effectively the same as calling #==, but typically overridden by descendants to provide meaningful semantics in case statements".
See http://andy-payne.com/2008/09/confusion-over-triple-equals/

What does a single splat/asterisk in a Ruby argument list mean? [duplicate]

This question already has an answer here:
naked asterisk as parameter in method definition: def f(*)
(1 answer)
Closed 10 years ago.
I was poking through the Rails 3 ActiveRecord source code today and found a method where the entire parameter list was a single asterisk.
def save(*)
I couldn't find a good description of what this does (though I have some ideas based on what I know about splat arguments).
What does it do, and why would you use it?
It means it can have any number of arguments (including zero) and it discards all those arguments.

Resources