Module: Kolom::MetaProgramming
- Defined in:
- lib/kolom/metaprogramming.rb
Overview
Advanced features for metaprogramming
Defined Under Namespace
Classes: DSLContext
Class Method Summary collapse
-
.create_alias(obj, new_name, old_name) ⇒ Object
Method aliasing in Bengali.
- .create_dsl(&block) ⇒ Object
-
.define_dynamic_method(obj, method_name, &block) ⇒ Object
Dynamic method generation.
-
.trace_method(klass, method_name) ⇒ Object
Method tracing for debugging.
Class Method Details
.create_alias(obj, new_name, old_name) ⇒ Object
Method aliasing in Bengali
10 11 12 13 14 |
# File 'lib/kolom/metaprogramming.rb', line 10 def self.create_alias(obj, new_name, old_name) obj.singleton_class.class_eval do alias_method new_name.to_sym, old_name.to_sym end end |
.create_dsl(&block) ⇒ Object
56 57 58 59 |
# File 'lib/kolom/metaprogramming.rb', line 56 def self.create_dsl(&block) context = DSLContext.new context.evaluate(&block) end |
.define_dynamic_method(obj, method_name, &block) ⇒ Object
Dynamic method generation
5 6 7 |
# File 'lib/kolom/metaprogramming.rb', line 5 def self.define_dynamic_method(obj, method_name, &block) obj.define_singleton_method(method_name, &block) end |
.trace_method(klass, method_name) ⇒ Object
Method tracing for debugging
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/kolom/metaprogramming.rb', line 17 def self.trace_method(klass, method_name) original_method = klass.instance_method(method_name) klass.class_eval do define_method(method_name) do |*args, &block| puts "Calling: #{method_name} with #{args.inspect}" result = original_method.bind(self).call(*args, &block) puts "Result: #{result.inspect}" result end end end |