class Object
Public Instance Methods
_?()
click to toggle source
# File lib/ext/object.rb, line 45 def _?() a? NilClass, FalseClass end
__mobj__parent(rent = :"__mobj__parent")
click to toggle source
# File lib/ext/object.rb, line 103 def __mobj__parent(rent = :"__mobj__parent") unless rent == :"__mobj__parent" @__mobj__parent = rent == self ? nil : rent end @__mobj__parent end
__mobj__parent?()
click to toggle source
# File lib/ext/object.rb, line 99 def __mobj__parent?() !@__mobj__parent.nil? end
__mobj__reparent()
click to toggle source
# File lib/ext/object.rb, line 95 def __mobj__reparent() values.each { |v| v.__mobj__parent(self); v.__mobj__reparent } if respond_to? :values end
__mobj__root()
click to toggle source
# File lib/ext/object.rb, line 91 def __mobj__root() __mobj__parent.nil? || __mobj__parent == self ? self : __mobj__parent.__mobj__root end
a?(*kls)
click to toggle source
# File lib/ext/object.rb, line 31 def a?(*kls) kls.when.mt?.be!([Array]).any? { |k| is_a? k } end
attempt(value=:root)
click to toggle source
# File lib/ext/object.rb, line 110 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.p? value.call([name] + args, &block) elsif value.h? && value.ki?(name) value[name].when.p?.call(*args, &block) else value == :root ? self : value end end end
c?()
click to toggle source
# File lib/ext/object.rb, line 43 def c?() a? Array, Hash end
f!()
click to toggle source
# File lib/ext/object.rb, line 56 def f!() to_s.scan(/[\d\.]+/).join.to_f end
f?()
click to toggle source
# File lib/ext/object.rb, line 39 def f?() a? Float end
fals?(*)
click to toggle source
# File lib/ext/object.rb, line 18 def fals?(*) nil end
h?()
click to toggle source
# File lib/ext/object.rb, line 42 def h?() a? Hash end
i!()
click to toggle source
# File lib/ext/object.rb, line 55 def i!() to_s.scan(/[\d\.]+/).join.to_i end
i?()
click to toggle source
# File lib/ext/object.rb, line 38 def i?() a? Fixnum end
iff?(value = nil, &block)
click to toggle source
# File lib/ext/object.rb, line 20 def iff?(value = nil, &block) block ? instance_exec(value, &block) : value end
iffn?(_=nil)
click to toggle source
# File lib/ext/object.rb, line 21 def iffn?(_=nil) nil end
m?()
click to toggle source
# File lib/ext/object.rb, line 36 def m?() a? Symbol end
n?()
click to toggle source
# File lib/ext/object.rb, line 40 def n?() a? Fixnum, Float end
nil!(*)
click to toggle source
# File lib/ext/object.rb, line 6 def nil!(*) self end
null!(*)
click to toggle source
# File lib/ext/object.rb, line 5 def null!(*) self end
o?()
click to toggle source
# File lib/ext/object.rb, line 53 def o?() !un? end
p?()
click to toggle source
# File lib/ext/object.rb, line 35 def p?() a? Proc end
rand?()
click to toggle source
# File lib/ext/object.rb, line 79 def rand? rand(1000000).odd? end
responds_to?(*any)
click to toggle source
# File lib/ext/object.rb, line 23 def responds_to?(*any) any.flatten.select { |method| respond_to?(method) }.realize! end
responds_to_all?(*all)
click to toggle source
# File lib/ext/object.rb, line 27 def responds_to_all?(*all) responds_to?(all) == all end
s!()
click to toggle source
# File lib/ext/object.rb, line 57 def s!() to_s end
s?()
click to toggle source
# File lib/ext/object.rb, line 37 def s?() a? String end
sym()
click to toggle source
# File lib/ext/object.rb, line 83 def sym() if respond_to?(:to_sym) to_sym else to_s.to_sym end end
tru?(t=true, _=nil, &block)
click to toggle source
# File lib/ext/object.rb, line 17 def tru?(t=true, _=nil, &block) block ? instance_exec(t, &block) : t end
try?(default=nil, &block)
click to toggle source
# File lib/ext/object.rb, line 124 def try?(default=nil, &block) Forwarder.new do |name, *args, &fblock| if methods(true).include?(name) __send__(name, *args, &fblock) elsif h? && ki?(name) self[name] end || (block ? instance_exec(*[*default], &block) : default) || nil.null! end end
Also aliased as: ifnil
un?()
click to toggle source
# File lib/ext/object.rb, line 49 def un?() _? || (s? && s !~ /\S/) || (c? && mt?) || (n? && z0?) end
up!(*args)
click to toggle source
# File lib/ext/object.rb, line 60 def up!(*args) if a? each { |i| i.up!(*args) } else if responds_to_all? :assign_attributes, :save args.select(&:h?).each do |arg| assign_attributes(arg) end save(validate:false) elsif responds_to? :update_attribute args.select(&:h?).each do |arg| arg.each do |k, v| update_attribute(k, v) end end end end end
when(val=:noval)
click to toggle source
# File lib/ext/object.rb, line 136 def when(val=:noval) iam = self return val == self ? self : Forwarder.new do |name, *args, &block| iam.define_singleton_method(:else) { |*vars| self } iam end if val != :noval Forwarder.new do |name, *args, &block| if (iam.respond_to?(name) || iam.methods.include?(name)) && (got = iam.__send__(name, *args, &block)) thn = Forwarder.new do |name, *inargs, &block| if name.sym == :then if block ret = iam.instance_exec(*inargs, &block) ret.define_singleton_method(:else) { |*vars| self } ret elsif inargs.mt? thn else ret = inargs.sequester! ret.define_singleton_method(:else) { |*vars| self } ret end else ret = __send__(name, *inargs, &block) ret.define_singleton_method(:else) { |*vars, &blk| if vars.mt? && block._? Forwarder.new { ret } else ret end } ret end end else ret = Forwarder.new do |name, *args, &block| if name.sym == :then els = Forwarder.new do |name, *targs, &block| if name.sym == :else if block iam.instance_exec(*targs, &block) elsif targs.mt? Forwarder.new { |name, *eargs, &block| __send__(name, *eargs, &block) } else targs.sequester! end else els end end else iam end end end end end
Also aliased as: if?
wrap!(*args, &block)
click to toggle source
# File lib/ext/object.rb, line 8 def wrap!(*args, &block) block ? instance_exec(*args, &block) : args.sequester! end
z0?()
click to toggle source
# File lib/ext/object.rb, line 47 def z0?() respond_to?(:zero?) ? zero? : f!.zero? end
zeno!()
click to toggle source
# File lib/ext/object.rb, line 58 def zeno!() z0? ? 1.0 : self end