Skip to content

Instantly share code, notes, and snippets.

@tjeden
Created August 5, 2014 08:01
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 tjeden/8453f29c5cd2f0146461 to your computer and use it in GitHub Desktop.
Save tjeden/8453f29c5cd2f0146461 to your computer and use it in GitHub Desktop.
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