Created
January 23, 2011 20:13
-
-
Save lucascaton/792391 to your computer and use it in GitHub Desktop.
Just 4fun =]
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 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