class Gen::Method
Public Class Methods
def_block_gen(name, initializer=name.to_s, default_args=nil)
click to toggle source
define a block generator on both the class and the instance
# File lib/gen/method.rb, line 11 def self.def_block_gen(name, initializer=name.to_s, default_args=nil) def_self "#{name}_block".to_sym do |code_lines=nil, args=default_args, &block| code_lines ||= block.call ["#{initializer} do #{args && "|#{args}|"}", indent(code_lines), "end"].join("\n") end end
def_self(method_name, &block)
click to toggle source
define a method on both the class and the instance
# File lib/gen/method.rb, line 5 def self.def_self(method_name, &block) define_method method_name, block # defines instance method define_singleton_method method_name, block # defines class method end