Guest User

Untitled

a guest
Jul 18th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. class Example
  2.  
  3. def initialize(name)
  4.  
  5. # this means there is an instance var of name in this object.
  6. @name = name
  7. end
  8.  
  9. # This is the ruby equivilant to this JS class method
  10. #
  11. # function name() {
  12. # return this.name;
  13. # }
  14. #
  15. def name
  16. @name
  17. end
  18.  
  19. # This is the ruby equivilant to this JS class method
  20. #
  21. # function setName(name) {
  22. # this.name = name;
  23. # }
  24. #
  25. def name=(name)
  26. @name = name
  27. end
  28.  
  29. end
  30.  
  31. # and here is a symbol shortcut in ruby
  32. class Example
  33.  
  34. attr :name
  35.  
  36. def initialize(name)
  37.  
  38. # this means there is an instance var of name in this object.
  39. @name = name
  40. end
  41.  
  42. end
Add Comment
Please, Sign In to add comment