Created
June 10, 2010 22:23
-
-
Save wijet/433725 to your computer and use it in GitHub Desktop.
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 A | |
def set_foo(foo) | |
@foo = foo | |
end | |
def get_foo | |
@foo | |
end | |
def set_bar(bar) | |
@bar = bar | |
end | |
def get_bar | |
@bar | |
end | |
def set_boo(boo) | |
@boo = boo | |
end | |
def get_boo | |
@boo | |
end | |
def to_s; "#{@foo}, #{@bar}, #{@boo}" end | |
end | |
a = A.new | |
a.set_foo 'Foo!!' | |
a.set_boo 'Boo!!' | |
a.set_bar 'Bar!!' | |
puts a |
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 A | |
[:foo, :bar, :boo].each do |attr| | |
define_method("set_#{attr}") do |value| | |
instance_variable_set("@#{attr}", value) | |
end | |
define_method("get_#{attr}") do | |
instance_variable_get("@#{attr}") | |
end | |
end | |
def to_s; "#{@foo}, #{@bar}, #{@boo}" end | |
end | |
a = A.new | |
a.set_foo 'Foo!!' | |
a.set_boo 'Boo!!' | |
a.set_bar 'Bar!!' | |
puts a |
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 A | |
[:foo, :bar, :boo].each do |attr| | |
define_method("#{attr}=") do |value| | |
instance_variable_set("@#{attr}", value) | |
end | |
define_method("#{attr}") do | |
instance_variable_get("@#{attr}") | |
end | |
end | |
def to_s; "#{@foo}, #{@bar}, #{@boo}" end | |
end | |
a = A.new | |
a.foo = 'Foo!!' | |
a.boo = 'Boo!!' | |
a.bar = 'Bar!!' | |
puts a |
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 A | |
attr_accessor :foo, :bar, :boo | |
def to_s; "#{@foo}, #{@bar}, #{@boo}" end | |
end | |
a = A.new | |
a.foo = 'Foo!!' | |
a.boo = 'Boo!!' | |
a.bar = 'Bar!!' | |
puts a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment