Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/nrser/labs/i8/surjection.rb,
lib/nrser/core_ext/object.rb,
lib/nrser/core_ext/object/lazy_var.rb
Overview
HACK
Instance Method Summary collapse
-
#as_array ⇒ Object
Call NRSER.as_array on ‘self`.
-
#as_hash(key = nil) ⇒ Object
Calls NRSER.as_hash on ‘self` with the provided `key`.
-
#falsy? ⇒ Boolean
See NRSER.falsy?.
- #if(proc_able, &block) ⇒ Object
-
#is?(other) ⇒ Boolean
Just an alias for ‘#equal?` that is easier for to remember.
-
#lazy_var(name, &block) ⇒ VALUE
If the instance variable ‘name` is not defined, sets it to the result of `&block`.
-
#thru {|_self| ... } ⇒ Object
Yield ‘self`.
-
#truthy? ⇒ Boolean
See NRSER.truthy?.
- #unless(proc_able, &block) ⇒ Object
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 |
#if(proc_able, &block) ⇒ Object
15 16 17 |
# File 'lib/nrser/labs/i8/surjection.rb', line 15 def if proc_able, &block block.call( self ) if proc_able.to_proc.call( 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 |
#unless(proc_able, &block) ⇒ Object
19 20 21 |
# File 'lib/nrser/labs/i8/surjection.rb', line 19 def unless proc_able, &block block.call( self ) unless proc_able.to_proc.call( self ) end |