[macruby-changes] [4600] DietRB/trunk

source_changes at macosforge.org source_changes at macosforge.org
Fri Oct 8 03:46:46 PDT 2010


Revision: 4600
          http://trac.macosforge.org/projects/ruby/changeset/4600
Author:   eloy.de.enige at gmail.com
Date:     2010-10-08 03:46:45 -0700 (Fri, 08 Oct 2010)
Log Message:
-----------
Allow Context#evaluate to accept objects htat respond to #to_s, like Source does.

From: Eloy Duran <eloy.de.enige at gmail.com>

Modified Paths:
--------------
    DietRB/trunk/lib/irb/context.rb
    DietRB/trunk/lib/irb/source.rb
    DietRB/trunk/spec/context_spec.rb
    DietRB/trunk/spec/source_spec.rb

Modified: DietRB/trunk/lib/irb/context.rb
===================================================================
--- DietRB/trunk/lib/irb/context.rb	2010-10-08 10:46:35 UTC (rev 4599)
+++ DietRB/trunk/lib/irb/context.rb	2010-10-08 10:46:45 UTC (rev 4600)
@@ -8,7 +8,7 @@
     end
     
     def evaluate(source)
-      eval(source, @binding)
+      eval(source.to_s, @binding)
     end
   end
 end
\ No newline at end of file

Modified: DietRB/trunk/lib/irb/source.rb
===================================================================
--- DietRB/trunk/lib/irb/source.rb	2010-10-08 10:46:35 UTC (rev 4599)
+++ DietRB/trunk/lib/irb/source.rb	2010-10-08 10:46:45 UTC (rev 4600)
@@ -19,6 +19,8 @@
       @buffer.join("\n")
     end
     
+    alias_method :to_s, :source
+    
     # Reflects on the accumulated source and returns the current code block
     # indentation level.
     def level

Modified: DietRB/trunk/spec/context_spec.rb
===================================================================
--- DietRB/trunk/spec/context_spec.rb	2010-10-08 10:46:35 UTC (rev 4599)
+++ DietRB/trunk/spec/context_spec.rb	2010-10-08 10:46:45 UTC (rev 4600)
@@ -22,4 +22,10 @@
   it "evaluates code with the object's binding" do
     @context.evaluate("self").should == main
   end
+  
+  it "coerces the given source to a string first" do
+    o = Object.new
+    def o.to_s; "self"; end
+    @context.evaluate(o).should == main
+  end
 end
\ No newline at end of file

Modified: DietRB/trunk/spec/source_spec.rb
===================================================================
--- DietRB/trunk/spec/source_spec.rb	2010-10-08 10:46:35 UTC (rev 4599)
+++ DietRB/trunk/spec/source_spec.rb	2010-10-08 10:46:45 UTC (rev 4600)
@@ -23,6 +23,12 @@
     @source.source.should == "foo\nbar"
   end
   
+  it "aliases #to_s to #source" do
+    @source << "foo"
+    @source << "bar"
+    @source.to_s.should == "foo\nbar"
+  end
+  
   it "returns that the accumulated source is a valid code block" do
     [
       ["def foo", "p :ok", "end"],
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101008/5516e770/attachment.html>


More information about the macruby-changes mailing list