Class: StringBuilder
- Inherits:
-
Object
show all
- Includes:
- Enumerable
- Defined in:
- lib/string_builder/core.rb,
lib/string_builder/version.rb
Constant Summary
collapse
- VERSION =
"0.1.0"
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of StringBuilder.
24
25
26
|
# File 'lib/string_builder/core.rb', line 24
def initialize
@buffer = []
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &_block) ⇒ Object
36
37
38
39
40
|
# File 'lib/string_builder/core.rb', line 36
def method_missing(name, *args, &_block)
tap do
@buffer << [name.to_s, args]
end
end
|
Instance Attribute Details
#buffer ⇒ Object
Returns the value of attribute buffer.
22
23
24
|
# File 'lib/string_builder/core.rb', line 22
def buffer
@buffer
end
|
Instance Method Details
#-(other) ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/string_builder/core.rb', line 54
def -(other)
tap do
case other
when MethodCallToken
@buffer << [other.base.to_s, []]
@buffer << :dash
@buffer << [other.name.to_s, other.args]
else
@buffer << [other.to_s, []] unless other.is_a?(StringBuilder)
@buffer << :dash
end
end
end
|
#/(_other) ⇒ Object
48
49
50
51
52
|
# File 'lib/string_builder/core.rb', line 48
def /(_other)
tap do
@buffer << :slash
end
end
|
#call(token) ⇒ Object
42
43
44
45
46
|
# File 'lib/string_builder/core.rb', line 42
def call(token)
tap do
@buffer << [token.to_s, []]
end
end
|
#each {|@buffer| ... } ⇒ Object
28
29
30
|
# File 'lib/string_builder/core.rb', line 28
def each
yield @buffer
end
|
#respond_to_missing?(_name, _include_private = false) ⇒ Boolean
32
33
34
|
# File 'lib/string_builder/core.rb', line 32
def respond_to_missing?(_name, _include_private = false)
true
end
|