Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/ext/object.rb
Instance Method Summary collapse
- #__mobj__parent(rent = :"__mobj__parent") ⇒ Object
- #__mobj__parent? ⇒ Boolean
- #__mobj__reparent ⇒ Object
- #__mobj__root ⇒ Object
- #attempt(value = :root) ⇒ Object
- #f! ⇒ Object
-
#i! ⇒ Object
xxx strip out junk?.
- #iff?(value = nil, &block) ⇒ Boolean
- #rand? ⇒ Boolean
- #sym ⇒ Object
- #try?(default = nil, &block) ⇒ Boolean (also: #ifnil)
- #when ⇒ Object (also: #if?)
- #z0? ⇒ Boolean
- #zeno! ⇒ Object
Instance Method Details
#__mobj__parent(rent = :"__mobj__parent") ⇒ Object
37 38 39 40 41 42 |
# File 'lib/ext/object.rb', line 37 def __mobj__parent(rent = :"__mobj__parent") unless rent == :"__mobj__parent" @__mobj__parent = rent == self ? nil : rent end @__mobj__parent end |
#__mobj__parent? ⇒ Boolean
33 34 35 |
# File 'lib/ext/object.rb', line 33 def __mobj__parent?() !@__mobj__parent.nil? end |
#__mobj__reparent ⇒ Object
29 30 31 |
# File 'lib/ext/object.rb', line 29 def __mobj__reparent() values.each { |v| v.__mobj__parent(self); v.__mobj__reparent } if respond_to? :values end |
#__mobj__root ⇒ Object
25 26 27 |
# File 'lib/ext/object.rb', line 25 def __mobj__root() __mobj__parent.nil? || __mobj__parent == self ? self : __mobj__parent.__mobj__root end |
#attempt(value = :root) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ext/object.rb', line 44 def attempt(value=:root) Forwarder.new do |name, *args, &block| if self.methods(true).include? name ##//use respond to? self.__send__(name, *args, &block) elsif value.is_a?(Proc) value.call([name] + args, &block) elsif value.is_a?(Hash) && value.ki?(name) value[name].when.is_a?(Proc).call(*args, &block) else value == :root ? self : value end end end |
#f! ⇒ Object
7 |
# File 'lib/ext/object.rb', line 7 def f!() to_s.scan(/[\d\.]+/).join.to_f end |
#i! ⇒ Object
xxx strip out junk?
6 |
# File 'lib/ext/object.rb', line 6 def i!() to_s.scan(/[\d\.]+/).join.to_i end |
#iff?(value = nil, &block) ⇒ Boolean
102 103 104 |
# File 'lib/ext/object.rb', line 102 def iff?(value = nil, &block) block ? instance_exec(value, &block) : value end |
#rand? ⇒ Boolean
13 14 15 |
# File 'lib/ext/object.rb', line 13 def rand? rand(1000000).odd? end |
#sym ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/ext/object.rb', line 17 def sym() if respond_to?(:to_sym) to_sym else to_s.to_sym end end |
#try?(default = nil, &block) ⇒ Boolean Also known as: ifnil
58 59 60 61 62 63 64 65 66 |
# File 'lib/ext/object.rb', line 58 def try?(default=nil, &block) Forwarder.new do |name, *args, &fblock| if methods(true).include?(name) __send__(name, *args, &fblock) elsif is_a?(Hash) && ki?(name) self[name] end || (block ? instance_exec(*[*default], &block) : default) || nil.null! end end |
#when ⇒ Object Also known as: if?
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/ext/object.rb', line 70 def when Forwarder.new do |name, *args, &block| if methods.include?(name) && __send__(name, *args, &block) thn = Forwarder.new do |name, *args, &block| if name.sym == :then thn else ret = __send__(name, *args, &block) ret.define_singleton_method(:else) { Forwarder.new { ret } } ret end end else Forwarder.new do |name| if name.sym == :then els = Forwarder.new do |name| if name.sym == :else Forwarder.new { |name, *args, &block| __send__(name, *args, &block) } else els end end else self end end end end end |
#z0? ⇒ Boolean
8 |
# File 'lib/ext/object.rb', line 8 def z0?() respond_to?(:zero?) ? zero? : f!.zero? end |
#zeno! ⇒ Object
9 |
# File 'lib/ext/object.rb', line 9 def zeno!() z0? ? 1.0 : self end |