Created
June 28, 2016 07:47
-
-
Save stevenocchipinti/9abb260b24a93896c740730b62243073 to your computer and use it in GitHub Desktop.
A simple demonstration of classes in Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# person.rb | |
# | |
# This is a simple Person class | |
# It really doesn't do much, but it demonstrates the use of classes in Ruby | |
# | |
class Person | |
attr_accessor :name | |
def initialize(name) | |
@name = name | |
end | |
def say(text) | |
puts "#{name} says: '#{text}'" | |
end | |
end | |
@bob = Person.new("Bob") | |
@bob.say "Hello world" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment