Skip to content

Instantly share code, notes, and snippets.

@lucascaton
Created January 23, 2011 20:13
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 lucascaton/792391 to your computer and use it in GitHub Desktop.
Save lucascaton/792391 to your computer and use it in GitHub Desktop.
Just 4fun =]
class Class
def sets_gets(*args)
args.each do |arg|
define_method(arg) { eval "@#{arg}" }
define_method("#{arg}=".to_sym) { |param| eval "@#{arg}=param" }
end
end
end
class Person
sets_gets :name, :age, :work_area
def initialize(name, age, work_area)
@name, @age, @work_area = name, age, work_area
end
end
p = Person.new 'Lucas', 23, 'ti'
puts "#{p.name} is #{p.age} years old and works with #{p.work_area}"
p.name = 'Lilyh'
p.age = 19
p.work_area= 'admin'
puts "#{p.name} is #{p.age} years old and works with #{p.work_area}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment