Module: MethodAttributes
- Extended by:
- MethodAttributes
- Included in:
- MethodAttributes
- Defined in:
- lib/clean-annotations/method_attr.rb
Constant Summary collapse
- @@GLOBAL_OPTS =
{}
- @@METHOD_OPTS =
{}
Instance Method Summary collapse
Instance Method Details
#define(klass, param_name, &block) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/clean-annotations/method_attr.rb', line 7 def define klass, param_name, &block klass.define_singleton_method(param_name) do |*args| @@METHOD_OPTS[param_name] ||= [] @@METHOD_OPTS[param_name].push block ? block.call(*args) : args[0] end klass.define_singleton_method(:method_added) do |name| return unless @@METHOD_OPTS.keys.first @@GLOBAL_OPTS[to_s] ||= {} @@GLOBAL_OPTS[to_s][name] = @@METHOD_OPTS.dup @@METHOD_OPTS.clear end end |
#get(klass, method_name = nil) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/clean-annotations/method_attr.rb', line 22 def get klass, method_name=nil return @@GLOBAL_OPTS[klass.to_s] unless method_name klass.ancestors.map(&:to_s).each do |a_klass| v = @@GLOBAL_OPTS[a_klass][method_name] return v if v end end |