Hi !
I was wondering the logic behind :
name = gets.chomp
I start to learn Ruby and it seems easy to understand we can set a value
to a variable or even a value that we want to “.gets” and “.chomp” but
how can we set directly a method (or several methods) to a variable.
To compare this to the English language I don’t quit understand a
definition which state : a noun = a verb.
If you’re starting with Ruby, you should probably leave assigning
methods to variables until later; once you’ve learned more about the
rest of the language.
The reason to keep a method inside a variable would usually be so that
you can pass it between objects and manipulate it. That’s
metaprogramming, which should probably be left alone until you have a
firm grasp of programming.
Here’s a way of calling a method without having to directly use the
class that the method belongs to: