Advertisement
obernardovieira

Basic Class - Name in initializer

Jan 15th, 2017
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.23 KB | None | 0 0
  1. # The Hello Class
  2. class Hello
  3.  
  4.   def initialize( name )
  5.     @name = name.capitalize
  6.   end
  7.  
  8.   def salute
  9.     puts "Hello #{@name}!"
  10.   end
  11.  
  12. end
  13.  
  14. # Create a new object
  15. h = Hello.new("Ruby")
  16.  
  17. # Output "Hello Ruby!"
  18. h.salute
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement