Class: Grammar::Ruby::CodeProxy
- Inherits:
-
Object
- Object
- Grammar::Ruby::CodeProxy
- Includes:
- Enumerable
- Defined in:
- lib/grammar/ruby.rb
Instance Method Summary collapse
- #display(port = $>) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(code) ⇒ CodeProxy
constructor
A new instance of CodeProxy.
- #inspect ⇒ Object
- #lined(port = $>) ⇒ Object
- #lines ⇒ Object
- #size ⇒ Object
- #to_s(s = "") ⇒ Object
- #to_str(s = "") ⇒ Object
Constructor Details
#initialize(code) ⇒ CodeProxy
Returns a new instance of CodeProxy.
119 120 121 |
# File 'lib/grammar/ruby.rb', line 119 def initialize(code) @code = code end |
Instance Method Details
#display(port = $>) ⇒ Object
149 150 151 |
# File 'lib/grammar/ruby.rb', line 149 def display(port=$>) each { |line| port.puts(line) } end |
#each(&block) ⇒ Object
134 135 136 137 138 139 140 141 |
# File 'lib/grammar/ruby.rb', line 134 def each(&block) text = lines i = 0 while i<text.size yield((" "*text[i]).concat(text[i+=1])) i += 1 end end |
#inspect ⇒ Object
122 123 124 |
# File 'lib/grammar/ruby.rb', line 122 def inspect @code._inspect end |
#lined(port = $>) ⇒ Object
152 153 154 155 156 157 158 |
# File 'lib/grammar/ruby.rb', line 152 def lined(port=$>) f = "%#{size.to_s.size}i: " i = 0 each { |line| port.puts((f % (i+=1)).concat(line)) } end |
#lines ⇒ Object
125 126 127 128 129 130 |
# File 'lib/grammar/ruby.rb', line 125 def lines @text ||= begin @code._lines(text=[0,""]) text end end |
#size ⇒ Object
131 132 133 |
# File 'lib/grammar/ruby.rb', line 131 def size lines.size>>1 end |
#to_s(s = "") ⇒ Object
142 143 144 145 |
# File 'lib/grammar/ruby.rb', line 142 def to_s(s="") each { |line| s.concat(line) << ?\n } s.chomp! end |
#to_str(s = "") ⇒ Object
146 147 148 |
# File 'lib/grammar/ruby.rb', line 146 def to_str(s="") to_s(s) end |