Class: LucidProps
- Inherits:
-
Object
show all
- Defined in:
- lib/lucid_props.rb
Instance Method Summary
collapse
Constructor Details
#initialize(props_hash) ⇒ LucidProps
Returns a new instance of LucidProps.
2
3
4
5
6
7
8
|
# File 'lib/lucid_props.rb', line 2
def initialize(props_hash)
props_hash = {} unless props_hash
@props_hash = props_hash
if RUBY_ENGINE != 'opal'
@props_hash.freeze
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(prop_name, *args, &block) ⇒ Object
35
36
37
38
|
# File 'lib/lucid_props.rb', line 35
def method_missing(prop_name, *args, &block)
return @props_hash[prop_name] if @props_hash.key?(prop_name)
super(prop_name, *args, &block)
end
|
Instance Method Details
#[](prop_name) ⇒ Object
52
53
54
|
# File 'lib/lucid_props.rb', line 52
def [](prop_name)
@props_hash[prop_name]
end
|
#any? ⇒ Boolean
10
11
12
|
# File 'lib/lucid_props.rb', line 10
def any?
@props_hash.keys.size > 0
end
|
#key?(prop_name) ⇒ Boolean
Also known as:
has_key?
27
28
29
|
# File 'lib/lucid_props.rb', line 27
def key?(prop_name)
@props_hash.key?(prop_name)
end
|
#keys ⇒ Object
31
32
33
|
# File 'lib/lucid_props.rb', line 31
def keys
@props_hash.keys
end
|
#set(prop_name, value) ⇒ Object
40
41
42
|
# File 'lib/lucid_props.rb', line 40
def set(prop_name, value)
@props_hash[prop_name] = value
end
|
#to_h ⇒ Object
14
15
16
|
# File 'lib/lucid_props.rb', line 14
def to_h
@props_hash
end
|
#to_json ⇒ Object
44
45
46
|
# File 'lib/lucid_props.rb', line 44
def to_json
JSON.dump(to_transport)
end
|
#to_n ⇒ Object
48
49
50
|
# File 'lib/lucid_props.rb', line 48
def to_n
@props_hash.to_n
end
|
#to_transport ⇒ Object
18
19
20
|
# File 'lib/lucid_props.rb', line 18
def to_transport
{}.merge(@props_hash)
end
|