Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/volt/extra_core/true_false.rb,
lib/volt/extra_core/try.rb,
lib/volt/extra_core/blank.rb,
lib/volt/extra_core/object.rb,
lib/volt/reactive/reactive_value.rb,
lib/volt/extra_core/stringify_keys.rb
Overview
The true?/false? predicates are convience methods since if ..reactive_value.. does not correctly evaluate. The reason for this is that ruby currently does not allow anything besides nil and false to be falsy.
Defined Under Namespace
Instance Method Summary collapse
-
#and(other) ⇒ Object
Provides the same functionality as &&, but since ReactiveValue’s only work with method calls, we provide .and as a convience.
-
#blank? ⇒ Boolean
An object is blank if it’s false, empty, or a whitespace string.
- #cur ⇒ Object
-
#deep_clone ⇒ Object
TODO: Need a real implementation of this.
- #deep_cur ⇒ Object
- #false? ⇒ Boolean
- #html_inspect ⇒ Object
-
#instance_values ⇒ Object
Setup a default pretty_inspect alias_method :pretty_inspect, :inspect.
-
#or(other) ⇒ Object
Provides the same functionality as ||, but since ReactiveValue’s only work with method calls, we provide .or as a convience.
-
#present? ⇒ Boolean
An object is present if it’s not
blank?
. - #reactive? ⇒ Boolean
- #stringify_keys ⇒ Object
- #symbolize_keys ⇒ Object
- #true? ⇒ Boolean
- #try(*a, &b) ⇒ Object
Instance Method Details
#and(other) ⇒ Object
Provides the same functionality as &&, but since ReactiveValue’s only work with method calls, we provide .and as a convience
21 22 23 24 25 26 27 |
# File 'lib/volt/extra_core/object.rb', line 21 def and(other) if self.true? return other else return self end end |
#blank? ⇒ Boolean
An object is blank if it’s false, empty, or a whitespace string. For example, ”, ‘ ’, nil
, [], and {} are all blank.
This simplifies:
if address.nil? || address.empty?
…to:
if address.blank?
12 13 14 |
# File 'lib/volt/extra_core/blank.rb', line 12 def blank? respond_to?(:empty?) ? empty? : !self end |
#cur ⇒ Object
10 11 12 |
# File 'lib/volt/reactive/reactive_value.rb', line 10 def cur self end |
#deep_clone ⇒ Object
TODO: Need a real implementation of this
46 47 48 |
# File 'lib/volt/extra_core/object.rb', line 46 def deep_clone Marshal.load(Marshal.dump(self)) end |
#deep_cur ⇒ Object
37 38 39 |
# File 'lib/volt/extra_core/object.rb', line 37 def deep_cur self.cur end |
#html_inspect ⇒ Object
41 42 43 |
# File 'lib/volt/extra_core/object.rb', line 41 def html_inspect inspect.gsub('<', '<').gsub('>', '>') end |
#instance_values ⇒ Object
Setup a default pretty_inspect alias_method :pretty_inspect, :inspect
5 6 7 |
# File 'lib/volt/extra_core/object.rb', line 5 def instance_values Hash[instance_variables.map { |name| [name[1..-1], instance_variable_get(name)] }] end |
#or(other) ⇒ Object
Provides the same functionality as ||, but since ReactiveValue’s only work with method calls, we provide .or as a convience.
11 12 13 14 15 16 17 |
# File 'lib/volt/extra_core/object.rb', line 11 def or(other) if self.true? return self else return other end end |
#present? ⇒ Boolean
An object is present if it’s not blank?
.
17 18 19 |
# File 'lib/volt/extra_core/blank.rb', line 17 def present? !blank? end |
#reactive? ⇒ Boolean
14 15 16 |
# File 'lib/volt/reactive/reactive_value.rb', line 14 def reactive? false end |
#stringify_keys ⇒ Object
2 3 4 5 6 |
# File 'lib/volt/extra_core/stringify_keys.rb', line 2 def stringify_keys self.each_with_object({}) { |(key, value), hash| hash[key.to_s] = value } end |
#symbolize_keys ⇒ Object
8 9 10 11 12 |
# File 'lib/volt/extra_core/stringify_keys.rb', line 8 def symbolize_keys self.each_with_object({}) { |(key, value), hash| hash[key.to_sym] = value } end |
#try(*a, &b) ⇒ Object
27 28 29 |
# File 'lib/volt/extra_core/try.rb', line 27 def try end |