Last active
December 16, 2015 05:39
-
-
Save joallard/5385643 to your computer and use it in GitHub Desktop.
OOP Ruby Quickstart
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
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