Skip to content

Instantly share code, notes, and snippets.

@darinthompson
Created December 28, 2015 23:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darinthompson/47ceb7a4fa6f574fff87 to your computer and use it in GitHub Desktop.
Save darinthompson/47ceb7a4fa6f574fff87 to your computer and use it in GitHub Desktop.
updated from other gist
class Person
attr_accessor :name, :age
def initialize(name = nil, age = nil)
@name = name
@age = age
end
def get_name_from_user
if @name.nil?
puts "Hello, what is your name?"
@name = gets.chomp
end
@name
end
def get_age_from_user
if @age.nil?
puts "How old are you?"
@age = gets.chomp.to_i
end
@age
end
def greeting
puts "Hello #{@name}, who appears to be #{@age} years old!"
end
end
darin = Person.new()
darin.get_name_from_user
darin.get_age_from_user
darin.greeting
trevor = Person.new("Trevor", 25)
trevor.greeting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment