Sha256: 4e457961b9dbdffa58bcd4a301eb8d04ada1d4f12b1c10f450bd6ca299be4273
Contents?: true
Size: 1.46 KB
Versions: 1
Compression:
Stored size: 1.46 KB
Contents
class LocalRaiseError < StandardError end class Object def r(what=nil) opath = what.class.ancestors out = opath.join("\n> ") data = what.is_a?(Hash) ? JSON.pretty_generate(what) : what.ai(plain:true) out = [data, out, ''].join("\n\n-\n\n") raise LocalRaiseError.new out end def instance_variables_hash Hash[instance_variables.map { |name| [name, instance_variable_get(name)] } ] end def or(_or) self.blank? || self == 0 ? _or : self end def try(*args) return nil if self.class == NilClass self.send(*args) end def die(desc=nil, exp_object=nil) desc ||= 'died without desc' desc = '%s: %s' % [exp_object.class, desc] if exp_object raise desc end # this will capture plain Hash and HashWithIndifferentAccess def is_hash? self.class.to_s.index('Hash') ? true : false end def is_array? self.class.to_s.index('Array') ? true : false end def is_string? self.class.to_s == 'String' ? true : false end def is_false? self.class.name == 'FalseClass' ? true : false end def is_true? self ? true :false end def is_numeric? Float(self) != nil rescue false end def is_symbol? self.class.to_s == 'Symbol' ? true : false end def is_boolean? self.class == TrueClass || self.class == FalseClass end end # if we dont have awesome print in prodction, define mock method(:ap) rescue Proc.new do class Object def ap(*args) puts args end end end.call
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
lux-fw-0.1.17 | ./lib/overload/object.rb |