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

Classes: NilProxy, TryProxy

Instance Method Summary collapse

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?

Returns:



12
13
14
# File 'lib/volt/extra_core/blank.rb', line 12

def blank?
  respond_to?(:empty?) ? empty? : !self
end

#curObject



10
11
12
# File 'lib/volt/reactive/reactive_value.rb', line 10

def cur
  self
end

#deep_cloneObject

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_curObject



37
38
39
# File 'lib/volt/extra_core/object.rb', line 37

def deep_cur
  self.cur
end

#false?Boolean

Returns:



10
11
12
# File 'lib/volt/extra_core/true_false.rb', line 10

def false?
  false
end

#html_inspectObject



41
42
43
# File 'lib/volt/extra_core/object.rb', line 41

def html_inspect
  inspect.gsub('<', '&lt;').gsub('>', '&gt;')
end

#instance_valuesObject

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?.

Returns:



17
18
19
# File 'lib/volt/extra_core/blank.rb', line 17

def present?
  !blank?
end

#reactive?Boolean

Returns:



14
15
16
# File 'lib/volt/reactive/reactive_value.rb', line 14

def reactive?
  false
end

#stringify_keysObject



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_keysObject



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

#true?Boolean

Returns:



6
7
8
# File 'lib/volt/extra_core/true_false.rb', line 6

def true?
  true
end

#try(*a, &b) ⇒ Object



27
28
29
# File 'lib/volt/extra_core/try.rb', line 27

def try

end