can_has_meta
this gem is meta
- Author
-
Ben Burkert ([email protected])
- Version
-
0.1.0
- Copyright
-
Copyright © 2008 Ben Burkert. All rights reserved.
- License
-
New BSD License (opensource.org/licenses/bsd-license.php)
- Website
- Repository
-
git://github.com/benburkert/can_has_meta.git
Dependencies
Basic Usage
can_has_meta adds three new items to your meta programming toolshed.
Object#instance_eval(*args, &block)
instance_eval has been modified to allow parameters to the block:
"abc".instance_eval("def") do |s|
p self << s # => "abcdef"
end
Module#macros(&block)
macros evaluates the block in the including class’s class, got it? Basically, it makes it super easy to add “acts_as_*” style methods:
module Foo
macros do
def acts_as_foo
def baz
"FOO-BAR-BAZ!"
end
end
end
end
class Bar
include Foo
acts_as_foo
end
p Bar.new.baz # => "FOO-BAR-BAZ"
Module#mixins(&block)
mixins evaluates the block in the including class’ instance. This allows you to manipulate the type including the module directly.
module Foo
p self
mixins do
p self
def ; end
end
end
# => Foo
module Bar
include Foo
end
# => Bar
class Baz
include Bar
end
# => Baz