Class: Code
Overview
Instance Method Summary collapse
- #+(arg) ⇒ Object
- #<<(arg) ⇒ Object
- #inspect ⇒ String
-
#map_non_code_parts {|part| ... } ⇒ Code
A Code with #non_code_parts mapped by the passed block.
- #metadata(*args) ⇒ Object
- #non_code_parts ⇒ Enumerable<Object>
- #to_s ⇒ String
Instance Method Details
#+(str) ⇒ Code #+(code) ⇒ Code
62 63 64 65 66 67 |
# File 'lib/code.rb', line 62 def + arg case arg when String then self + Code.new([arg]) when Code then Code.new(self.parts + arg.parts) end end |
#<<(str) ⇒ self #<<(code) ⇒ self
77 78 79 80 81 82 |
# File 'lib/code.rb', line 77 def << arg case arg when String then self << Code.new([arg]) when Code then @parts.concat(arg.parts); self end end |
#inspect ⇒ String
127 128 129 |
# File 'lib/code.rb', line 127 def inspect Inspectable.new(@parts, ).inspect end |
#map_non_code_parts {|part| ... } ⇒ Code
Returns a Code with #non_code_parts mapped by the passed block.
101 102 103 104 105 106 107 108 109 110 |
# File 'lib/code.rb', line 101 def map_non_code_parts(&f) Code.new( @parts.map do |part| case part when String then part when NonCodePart then f.(part.data) end end ) end |
#metadata(obj) ⇒ Code #metadata ⇒ Object?
91 92 93 94 95 96 |
# File 'lib/code.rb', line 91 def (*args) if args.empty? then else Code.new(@parts, args.first) end end |
#non_code_parts ⇒ Enumerable<Object>
114 115 116 |
# File 'lib/code.rb', line 114 def non_code_parts @parts.select { |part| part.is_a? NonCodePart }.map(&:data) end |
#to_s ⇒ String
119 120 121 122 123 124 |
# File 'lib/code.rb', line 119 def to_s if (x = @parts.find { |part| part.is_a? NonCodePart }) then raise "non-code part: #{x.inspect}" end @parts.join end |