#!/usr/bin/env ruby -Ku
# -*- encoding: utf-8 -*-
class T
def self.access_attribute(name)
define_method(name) do
instance_variable_get("@#{name}")
end
define_method("#{name}=") do |word|
instance_variable_set("@#{name}", word)
end
end
end
class D < T
access_attribute :hello
def initialize(hello)
@hello = hello
end
end
d = D.new('Yah!')
p d.hello
d.hello = "YoY"
p d.hello
Saturday, May 01, 2010
attr_accessor
attr_accessor
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment