1.9.3p0 :016 > def my_method(message)
puts "Hello," + message
end
puts "Hello," + message
end
Method call
1.9.3p0 :016 > my_method("World")
=> Hello, 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
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
=> Author x-author is written books - book1,book2,book3
No comments:
Post a Comment