Module: Ryo
- Extended by:
- Enumerable, Keywords, Reflect
- Defined in:
- lib/ryo.rb,
lib/ryo/version.rb
Overview
The Ryo module implements most of its behavior as singleton methods that are inherited from the Ryo::Reflect, and Ryo:Keywords modules.
Defined Under Namespace
Modules: Builder, Enumerable, JSON, Keywords, Reflect, Utils, YAML Classes: BasicObject, Function, Memo, Object
Constant Summary collapse
- VERSION =
"0.5.6"
Class Method Summary collapse
-
.BasicObject(props, prototype = nil) ⇒ Ryo::BasicObject
Returns an instance of Ryo::BasicObject.
-
.dup(ryo) ⇒ <Ryo::Object, Ryo::BasicObject>
Duplicates a Ryo object, and its prototype(s).
-
.extend!(ryo, mod) ⇒ <Ryo::Object, Ryo::BasicObject>
Returns an extended Ryo object.
-
.from(props, prototype = nil) ⇒ Ryo::Object
Creates a Ryo object by recursively walking a Hash object.
-
.memo(&b) ⇒ Ryo::Memo
(also: lazy)
Creates a memoized Ryo value.
-
.Object(props, prototype = nil) ⇒ Ryo::Object
Returns an instance of Ryo::Object.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Returns true other is equal to self.
-
#[](property) ⇒ <Object, BasicObject>?
Returns the property's value, or nil.
-
#[]=(property, value)
Assign a property.
-
#__proto__ ⇒ <Ryo::Object, Ryo::BasicObject>?
Returns the prototype of self, or nil if self has no prototype.
-
#inspect ⇒ String
Returns a String representation of a Ryo object.
-
#to_h ⇒ Hash
(also: #to_hash)
Returns the lookup table of a Ryo object.
Methods included from Reflect
assign, call_method, class_of, define_property, delete!, equal?, function?, inspect_object, memo?, properties_of, property?, prototype_chain_of, prototype_of, ryo?, set_prototype_of, set_table_of, table_of
Methods included from Keywords
Methods included from Enumerable
all?, any?, each, each_ryo, find, map, map!, reject, reject!, select, select!
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &b) ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/ryo.rb', line 174 def method_missing(name, *args, &b) property = name.to_s if property[-1] == "=" property = property[0..-2] self[property] = args.first elsif Ryo.property?(self, property) self[property] elsif @_proto Ryo.call_method(@_proto, name, *args, &b) .tap { _1.bind!(self) if Ryo.function?(_1) } end end |
Class Method Details
.BasicObject(props, prototype = nil) ⇒ Ryo::BasicObject
Returns an instance of Ryo::BasicObject
52 53 54 |
# File 'lib/ryo/basic_object.rb', line 52 def Ryo.BasicObject(props, prototype = nil) Ryo::BasicObject.create(props, prototype) end |
.dup(ryo) ⇒ <Ryo::Object, Ryo::BasicObject>
Duplicates a Ryo object, and its prototype(s).
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/ryo.rb', line 50 def self.dup(ryo) duplicate = extend!( kernel(:dup).bind_call(ryo), self ) if proto = prototype_of(duplicate) set_prototype_of(duplicate, dup(proto)) end duplicate end |
.extend!(ryo, mod) ⇒ <Ryo::Object, Ryo::BasicObject>
Returns an extended Ryo object
39 40 41 |
# File 'lib/ryo.rb', line 39 def self.extend!(ryo, mod) kernel(:extend).bind_call(ryo, mod) end |
.from(props, prototype = nil) ⇒ Ryo::Object
Creates a Ryo object by recursively walking a Hash object
82 83 84 |
# File 'lib/ryo.rb', line 82 def self.from(props, prototype = nil) Ryo::Object.from(props, prototype) end |
.memo(&b) ⇒ Ryo::Memo Also known as: lazy
Creates a memoized Ryo value
68 69 70 |
# File 'lib/ryo.rb', line 68 def self.memo(&b) Ryo::Memo.new(&b) end |
.Object(props, prototype = nil) ⇒ Ryo::Object
Returns an instance of Ryo::Object
52 53 54 |
# File 'lib/ryo/object.rb', line 52 def Ryo.Object(props, prototype = nil) Ryo::Object.create(props, prototype) end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Returns true other is equal to self
128 129 130 131 132 133 134 135 136 |
# File 'lib/ryo.rb', line 128 def ==(other) if Ryo.ryo?(other) @_table == Ryo.table_of(other) else other = Hash.try_convert(other) return false unless other @_table == other.map { [_1.to_s, _2] }.to_h end end |
#[](property) ⇒ <Object, BasicObject>?
This method will first query self for a property, and if the property is not found the query is sent to Ryo#proto instead
Returns the property's value, or nil
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/ryo.rb', line 102 def [](property) property = property.to_s if Ryo.property?(self, property) v = @_table[property] Ryo.memo?(v) ? self[property] = v.call : v else return unless @_proto Ryo.call_method(@_proto, property) end end |
#[]=(property, value)
This method returns an undefined value.
Assign a property
120 121 122 |
# File 'lib/ryo.rb', line 120 def []=(property, value) Ryo.define_property(self, property.to_s, value) end |
#__proto__ ⇒ <Ryo::Object, Ryo::BasicObject>?
Returns the prototype of self, or nil if self has no prototype
89 90 91 |
# File 'lib/ryo.rb', line 89 def __proto__ @_proto end |
#inspect ⇒ String
Returns a String representation of a Ryo object
142 143 144 |
# File 'lib/ryo.rb', line 142 def inspect Ryo.inspect_object(self) end |