Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/nrser/core_ext/object.rb,
lib/nrser/core_ext/object/lazy_var.rb
Instance Method Summary collapse
-
#as_array ⇒ Object
Call NRSER.as_array on
self. -
#as_hash(key = nil) ⇒ Object
Calls NRSER.as_hash on
selfwith the providedkey. -
#falsy? ⇒ Boolean
See NRSER.falsy?.
-
#is?(other) ⇒ Boolean
Just an alias for
#equal?that is easier for to remember. -
#lazy_var(name, &block) ⇒ VALUE
If the instance variable
nameis not defined, sets it to the result of ‘&block`. -
#thru {|_self| ... } ⇒ Object
Yield
self. -
#truthy? ⇒ Boolean
See NRSER.truthy?.
Instance Method Details
#as_array ⇒ Object
Call NRSER.as_array on self.
42 43 44 |
# File 'lib/nrser/core_ext/object.rb', line 42 def as_array NRSER.as_array self end |
#as_hash(key = nil) ⇒ Object
Calls NRSER.as_hash on self with the provided key.
36 37 38 |
# File 'lib/nrser/core_ext/object.rb', line 36 def as_hash key = nil NRSER.as_hash self, key end |
#falsy? ⇒ Boolean
See NRSER.falsy?.
30 31 32 |
# File 'lib/nrser/core_ext/object.rb', line 30 def falsy? NRSER.falsy? self end |
#is?(other) ⇒ Boolean
Just an alias for #equal? that is easier for to remember.
18 19 20 |
# File 'lib/nrser/core_ext/object.rb', line 18 def is? other equal? other end |
#lazy_var(name, &block) ⇒ VALUE
If the instance variable name is not defined, sets it to the result of ‘&block`. Always returns the instance variable’s value.
Useful for lazy values that can be nil or false, since ‘||=` will always re-evaluate in their cases.
23 24 25 26 27 28 29 |
# File 'lib/nrser/core_ext/object/lazy_var.rb', line 23 def lazy_var name, &block unless instance_variable_defined? name instance_variable_set name, block.call end instance_variable_get name end |
#thru {|_self| ... } ⇒ Object
Yield self. Analogous to #tap but returns the result of the invoked block.
5 6 7 |
# File 'lib/nrser/core_ext/object.rb', line 5 def thru yield self end |
#truthy? ⇒ Boolean
See NRSER.truthy?.
24 25 26 |
# File 'lib/nrser/core_ext/object.rb', line 24 def truthy? NRSER.truthy? self end |