Monday, May 21, 2012

Ruby method - 1.9.3

Simple ruby method definition

1.9.3p0 :016 > def my_method(message)
puts "Hello," + message
end

Method call

1.9.3p0 :016 > my_method("World")
=> Hello, World

Ruby method with variable length parameters

1.9.3p0 :016 > def author_books(author, *books)
puts "Author #{author} is written books - #{books.join(', ')}"
end

Method call

1.9.3p0 :016 >author_books("x-author","book1","book2","book3")
=> Author x-author is written books - book1,book2,book3

No comments:

Post a Comment