..


Sponsored Links

How do you define a method in Ruby?

The def statement to define a method, it follows the method name and parameters to be used written in brackets, before closing the block can indicate that the instructions above will make the method return value and an (optional) via return ; make an example:

 



 # Definition of a method in Ruby









 # Method and parameters







 final half (country)



  



 # Instructions



  



 puts 'I was born in' + country + ''.



  



 # Return value



  



 return 'Did not you know?'







 # End of definition block







 end



 





 # Method call







 puts (half ('Italy'))









 = Begin

 





 La Chimere printing:







 I was born in Italy.







 Did not you know?







 = End



In the same category ...
E-Learning
Ruby and Ruby on Rails (Course) Ruby and Ruby on Rails (Course)
Create software and Web applications with Ruby and RoR. From 39 €.
Sponsored Links