[macruby-changes] [4672] DietRB/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Fri Oct 8 03:57:27 PDT 2010
Revision: 4672
http://trac.macosforge.org/projects/ruby/changeset/4672
Author: eloy.de.enige at gmail.com
Date: 2010-10-08 03:57:26 -0700 (Fri, 08 Oct 2010)
Log Message:
-----------
Add IRB::Context#input_line which prints a prompt, the line, and then processes the line.
From: Eloy Duran <eloy.de.enige at gmail.com>
Modified Paths:
--------------
DietRB/trunk/bin/dietrb
DietRB/trunk/lib/irb/context.rb
DietRB/trunk/lib/irb/ext/history.rb
DietRB/trunk/spec/context_spec.rb
Modified: DietRB/trunk/bin/dietrb
===================================================================
--- DietRB/trunk/bin/dietrb 2010-10-08 10:57:15 UTC (rev 4671)
+++ DietRB/trunk/bin/dietrb 2010-10-08 10:57:26 UTC (rev 4672)
@@ -31,9 +31,6 @@
path = ARGV.shift
context = IRB::Context.new(self, TOPLEVEL_BINDING.dup)
File.open(path, 'r') do |file|
- file.each_line do |line|
- puts IRB.formatter.prompt(context) + line
- context.process_line(line)
- end
+ file.each_line { |line| context.input_line(line) }
end
end
\ No newline at end of file
Modified: DietRB/trunk/lib/irb/context.rb
===================================================================
--- DietRB/trunk/lib/irb/context.rb 2010-10-08 10:57:15 UTC (rev 4671)
+++ DietRB/trunk/lib/irb/context.rb 2010-10-08 10:57:26 UTC (rev 4672)
@@ -90,6 +90,11 @@
true
end
+ def input_line(line)
+ puts formatter.prompt(self) + line
+ process_line(line)
+ end
+
def formatter
IRB.formatter
end
Modified: DietRB/trunk/lib/irb/ext/history.rb
===================================================================
--- DietRB/trunk/lib/irb/ext/history.rb 2010-10-08 10:57:15 UTC (rev 4671)
+++ DietRB/trunk/lib/irb/ext/history.rb 2010-10-08 10:57:26 UTC (rev 4672)
@@ -53,17 +53,13 @@
# we don't want to execute history! again
@context.clear_buffer
- lines = if entry_or_range.is_a?(Range)
- entry_or_range.to_a.map { |i| Readline::HISTORY[i] }
+ if entry_or_range.is_a?(Range)
+ entry_or_range.to_a.each do |i|
+ @context.input_line(Readline::HISTORY[i])
+ end
else
- [Readline::HISTORY[entry_or_range]]
+ @context.input_line(Readline::HISTORY[entry_or_range])
end
-
- lines.each do |line|
- # TODO: this is also done by ./bin/dietrb when replaying a file
- puts IRB.formatter.prompt(@context) + line
- @context.process_line(line)
- end
end
end
end
Modified: DietRB/trunk/spec/context_spec.rb
===================================================================
--- DietRB/trunk/spec/context_spec.rb 2010-10-08 10:57:15 UTC (rev 4671)
+++ DietRB/trunk/spec/context_spec.rb 2010-10-08 10:57:26 UTC (rev 4672)
@@ -79,8 +79,8 @@
describe "IRB::Context, when evaluating source" do
before do
@context = IRB::Context.new(main)
- def @context.puts(string); @printed = string; end
- def @context.printed; @printed; end
+ def @context.printed; @printed ||= '' end
+ def @context.puts(string); printed << "#{string}\n" end
end
it "evaluates code with the object's binding" do
@@ -89,8 +89,7 @@
it "prints the result" do
@context.evaluate("Hash[:foo, :foo]")
- printed = @context.instance_variable_get(:@printed)
- printed.should == "=> {:foo=>:foo}"
+ @context.printed.should == "=> {:foo=>:foo}\n"
end
it "assigns the result to the local variable `_'" do
@@ -125,6 +124,12 @@
@context.process_line("end")
@context.printed.should.match /\(irb\):3:in.+\(irb\):2:in/m
end
+
+ it "inputs a line to be processed, skipping readline" do
+ expected = "#{@context.formatter.prompt(@context)}2 * 21\n=> 42\n"
+ @context.input_line("2 * 21")
+ @context.printed.should == expected
+ end
end
describe "IRB::Context, when receiving input" do
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101008/02413541/attachment.html>
More information about the macruby-changes
mailing list