Created
August 5, 2014 08:01
-
-
Save tjeden/8453f29c5cd2f0146461 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
module BasiaAttr | |
def basia_reader(method_name) | |
define_method(method_name) do | |
instance_variable_get("@#{method_name}".to_sym) | |
end | |
end | |
def basia_writer(method_name) | |
define_method("#{method_name}=") do |value| | |
instance_variable_set("@#{method_name}".to_sym, value) | |
end | |
end | |
def basia_accessor(*methods) | |
methods.each do |method_name| | |
basia_reader(method_name) | |
basia_writer(method_name) | |
end | |
end | |
end | |
class Hello | |
extend BasiaAttr | |
basia_accessor :rower, :samochod | |
end | |
hello = Hello.new | |
hello.rower = "To jest nierower" | |
hello.samochod = "To jest samochod" | |
puts hello.rower | |
puts hello.samochod |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment