Class: LucidProps

Inherits:
Object
  • 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
# File 'lib/lucid_props.rb', line 2

def initialize(props_hash)
  props_hash = {} unless props_hash
  @props_hash = props_hash
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(prop_name, *args, &block) ⇒ Object



36
37
38
39
# File 'lib/lucid_props.rb', line 36

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

RUBY_ENGINE



53
54
55
# File 'lib/lucid_props.rb', line 53

def [](prop_name)
  @props_hash[prop_name]
end

#[]=(prop_name, value) ⇒ Object



24
25
26
# File 'lib/lucid_props.rb', line 24

def []=(prop_name, value)
  @props_hash[prop_name] = value
end

#any?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/lucid_props.rb', line 7

def any?
  @props_hash.keys.size > 0
end

#key?(prop_name) ⇒ Boolean Also known as: has_key?

Returns:

  • (Boolean)


28
29
30
# File 'lib/lucid_props.rb', line 28

def key?(prop_name)
  @props_hash.key?(prop_name)
end

#keysObject



32
33
34
# File 'lib/lucid_props.rb', line 32

def keys
  @props_hash.keys
end

#set(prop_name, value) ⇒ Object



41
42
43
# File 'lib/lucid_props.rb', line 41

def set(prop_name, value)
  @props_hash[prop_name] = value
end

#to_hObject



11
12
13
# File 'lib/lucid_props.rb', line 11

def to_h
  @props_hash
end

#to_jsonObject



45
46
47
# File 'lib/lucid_props.rb', line 45

def to_json
  JSON.dump(to_transport)
end

#to_nObject



49
50
51
# File 'lib/lucid_props.rb', line 49

def to_n
  @props_hash.to_n
end

#to_transportObject



15
16
17
# File 'lib/lucid_props.rb', line 15

def to_transport
  {}.merge(@props_hash)
end