Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/volt/extra_core/true_false.rb,
lib/volt/extra_core/blank.rb,
lib/volt/extra_core/object.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.
Instance Method Summary collapse
-
#and(other) ⇒ Object
Provides the same functionality as &&, treats a nil model as falsy.
-
#blank? ⇒ Boolean
An object is blank if it’s false, empty, or a whitespace string.
-
#deep_clone ⇒ Object
TODO: Need a real implementation of this.
- #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 treats a nil model as falsy.
-
#present? ⇒ Boolean
An object is present if it’s not
blank?
. - #stringify_keys ⇒ Object
- #symbolize_keys ⇒ Object
- #true? ⇒ Boolean
Instance Method Details
#and(other) ⇒ Object
Provides the same functionality as &&, treats a nil model as falsy
19 20 21 22 23 24 25 |
# File 'lib/volt/extra_core/object.rb', line 19 def and(other) if self && !self.nil? 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 |
#deep_clone ⇒ Object
TODO: Need a real implementation of this
32 33 34 |
# File 'lib/volt/extra_core/object.rb', line 32 def deep_clone Marshal.load(Marshal.dump(self)) end |
#html_inspect ⇒ Object
27 28 29 |
# File 'lib/volt/extra_core/object.rb', line 27 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 treats a nil model as falsy
10 11 12 13 14 15 16 |
# File 'lib/volt/extra_core/object.rb', line 10 def or(other) if self && !self.nil? 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 |
#stringify_keys ⇒ Object
2 3 4 5 6 |
# File 'lib/volt/extra_core/stringify_keys.rb', line 2 def stringify_keys each_with_object({}) do |(key, value), hash| hash[key.to_s] = value end end |
#symbolize_keys ⇒ Object
8 9 10 11 12 |
# File 'lib/volt/extra_core/stringify_keys.rb', line 8 def symbolize_keys each_with_object({}) do |(key, value), hash| hash[key.to_sym] = value end end |