Class: One9::Method
- Inherits:
-
Object
- Object
- One9::Method
- Defined in:
- lib/one9/method.rb
Instance Attribute Summary collapse
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#message ⇒ Object
Returns the value of attribute message.
-
#meth ⇒ Object
Returns the value of attribute meth.
-
#name ⇒ Object
Returns the value of attribute name.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #class_method? ⇒ Boolean
- #exists? ⇒ Boolean
-
#initialize(name, options = {}) ⇒ Method
constructor
A new instance of Method.
- #real_klass ⇒ Object
Constructor Details
#initialize(name, options = {}) ⇒ Method
Returns a new instance of Method.
17 18 19 20 21 22 23 24 25 |
# File 'lib/one9/method.rb', line 17 def initialize(name, ={}) @name = name.to_s[/[.#]/] ? name : [:class] ? [:class] + name : raise(ArgumentError, "Method '#{name}' has an invalid name") @klass, @meth = @name.split(/[.#]/, 2) @message, @type = .values_at(:message, :type) @message ||= @type == :delete ? "This method does not exist in 1.9" : "This method has different behavior in 1.9" end |
Instance Attribute Details
#klass ⇒ Object
Returns the value of attribute klass.
3 4 5 |
# File 'lib/one9/method.rb', line 3 def klass @klass end |
#message ⇒ Object
Returns the value of attribute message.
3 4 5 |
# File 'lib/one9/method.rb', line 3 def @message end |
#meth ⇒ Object
Returns the value of attribute meth.
3 4 5 |
# File 'lib/one9/method.rb', line 3 def meth @meth end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/one9/method.rb', line 3 def name @name end |
#type ⇒ Object
Returns the value of attribute type.
3 4 5 |
# File 'lib/one9/method.rb', line 3 def type @type end |
Class Method Details
.any_const_get(name) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/one9/method.rb', line 4 def self.any_const_get(name) return name if name.is_a?(Module) begin klass = Object name.split('::').each {|e| klass = klass.const_get(e) } klass rescue nil end end |
Instance Method Details
#class_method? ⇒ Boolean
36 37 38 |
# File 'lib/one9/method.rb', line 36 def class_method? @name.include?('.') end |
#exists? ⇒ Boolean
31 32 33 34 |
# File 'lib/one9/method.rb', line 31 def exists? obj = class_method? ? (class << real_klass; self end) : real_klass obj.method_defined?(meth) || obj.private_method_defined?(meth) end |
#real_klass ⇒ Object
27 28 29 |
# File 'lib/one9/method.rb', line 27 def real_klass @real_klass ||= self.class.any_const_get(@klass) end |