Skip to content

Instantly share code, notes, and snippets.

@joallard
Last active December 16, 2015 05:39
Show Gist options
  • Save joallard/5385643 to your computer and use it in GitHub Desktop.
Save joallard/5385643 to your computer and use it in GitHub Desktop.
OOP Ruby Quickstart
class Person
attr_reader :name
# short for:
# def name
# @name
# end
def initialize(name)
@name = name
end
def introduce
puts "Hello, my name is #{@name}"
end
end
# jon is an instance of class Person
jon = Person.new("Jonathan")
jon.class # => Person
jon.name # => "Jonathan"
jon.introduce # Hello, my name is Jonathan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment