Class: Reight::Sprite
- Inherits:
-
RubySketch::Sprite
- Object
- RubySketch::Sprite
- Reight::Sprite
show all
- Defined in:
- lib/reight/sprite.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#[](key) ⇒ Object
-
#[]=(key, value) ⇒ Object
-
#initialize(*a, chip: nil, **k, &b) ⇒ Sprite
constructor
A new instance of Sprite.
-
#method_missing(name, *args, **kwargs, &block) ⇒ Object
-
#prop(name, value = NilClass, **values) ⇒ Object
-
#respond_to_missing?(name, include_private = false) ⇒ Boolean
Constructor Details
#initialize(*a, chip: nil, **k, &b) ⇒ Sprite
3
4
5
6
|
# File 'lib/reight/sprite.rb', line 3
def initialize(*a, chip: nil, **k, &b)
@chip, @props = chip, {}
super(*a, **k, &b)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, **kwargs, &block) ⇒ Object
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/reight/sprite.rb', line 31
def method_missing(name, *args, **kwargs, &block)
write = name.end_with? '='
key = write ? name.to_s.delete_suffix('=').to_sym : name
return super unless @props.key?(key)
if write
@props.[]=(key, *args)
else
@props[key]
end
end
|
Instance Attribute Details
#chip ⇒ Object
Returns the value of attribute chip.
10
11
12
|
# File 'lib/reight/sprite.rb', line 10
def chip
@chip
end
|
#map_chunk ⇒ Object
Returns the value of attribute map_chunk.
8
9
10
|
# File 'lib/reight/sprite.rb', line 8
def map_chunk
@map_chunk
end
|
#props ⇒ Object
Returns the value of attribute props.
10
11
12
|
# File 'lib/reight/sprite.rb', line 10
def props
@props
end
|
Instance Method Details
#[](key) ⇒ Object
18
19
20
|
# File 'lib/reight/sprite.rb', line 18
def [](key)
@props[key]
end
|
#[]=(key, value) ⇒ Object
22
23
24
|
# File 'lib/reight/sprite.rb', line 22
def []=(key, value)
@props[key] = value
end
|
#prop(name, value = NilClass, **values) ⇒ Object
12
13
14
15
16
|
# File 'lib/reight/sprite.rb', line 12
def prop(name, value = NilClass, **values)
@props[name] = value if value != NilClass
values.each {|k, v| @props[k] = v} unless values.empty?
@props[name]
end
|
#respond_to_missing?(name, include_private = false) ⇒ Boolean
26
27
28
29
|
# File 'lib/reight/sprite.rb', line 26
def respond_to_missing?(name, include_private = false)
name = name.to_s.delete_suffix('=').to_sym if name.end_with? '='
@props.key?(name) || super
end
|