Class: NsOptions::ProxyMethod
- Inherits:
-
Object
- Object
- NsOptions::ProxyMethod
- Defined in:
- lib/ns-options/proxy_method.rb
Instance Method Summary collapse
- #define(io = nil, from_caller = nil) ⇒ Object
- #define_on_class? ⇒ Boolean
-
#initialize(define_on, name, kind) ⇒ ProxyMethod
constructor
This class handles defining proxy class methods for classes or modules and an additional instance method for classes.
- #validate(io, from_caller) ⇒ Object
Constructor Details
#initialize(define_on, name, kind) ⇒ ProxyMethod
This class handles defining proxy class methods for classes or modules and an additional instance method for classes.
10 11 12 13 14 |
# File 'lib/ns-options/proxy_method.rb', line 10 def initialize(define_on, name, kind) @define_on, @name, @kind = define_on, name, kind @meth_extension_mixin = Module.new @meth_extension_mixin.class_eval proxy_meth_code end |
Instance Method Details
#define(io = nil, from_caller = nil) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/ns-options/proxy_method.rb', line 20 def define(io=nil, from_caller=nil) validate(io || $stdout, from_caller || caller) # covers defining the class-level method on Modules or Classes @define_on.send :extend, @meth_extension_mixin # covers defining the instance-level method on Classes @define_on.send :include, @meth_extension_mixin if define_on_class? end |
#define_on_class? ⇒ Boolean
16 17 18 |
# File 'lib/ns-options/proxy_method.rb', line 16 def define_on_class? !!@define_on.kind_of?(::Class) end |
#validate(io, from_caller) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/ns-options/proxy_method.rb', line 30 def validate(io, from_caller) return true unless not_recommended_meth_names.include?(@name.to_sym) io.puts "WARNING: Defining #{@kind} with the name `#{@name}' overwrites a"\ " method NsOptions::Proxy depends on and may cause it to not"\ " behave correctly." io.puts from_caller.first false end |