[macruby-changes] [4599] DietRB/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Fri Oct 8 03:46:36 PDT 2010
Revision: 4599
http://trac.macosforge.org/projects/ruby/changeset/4599
Author: eloy.de.enige at gmail.com
Date: 2010-10-08 03:46:35 -0700 (Fri, 08 Oct 2010)
Log Message:
-----------
Start on IRB::Context, which uses a copy of the binding of a given object to evaluate code in.
From: Eloy Duran <eloy.de.enige at gmail.com>
Modified Paths:
--------------
DietRB/trunk/spec/source_spec.rb
Added Paths:
-----------
DietRB/trunk/Rakefile
DietRB/trunk/lib/irb/context.rb
DietRB/trunk/lib/irb.rb
DietRB/trunk/spec/context_spec.rb
DietRB/trunk/spec/spec_helper.rb
Added: DietRB/trunk/Rakefile
===================================================================
--- DietRB/trunk/Rakefile (rev 0)
+++ DietRB/trunk/Rakefile 2010-10-08 10:46:35 UTC (rev 4599)
@@ -0,0 +1,11 @@
+task :default => :spec
+
+desc "Run the specs"
+task :spec do
+ sh "macbacon #{FileList['spec/**/*_spec.rb'].join(' ')}"
+end
+
+desc "Run specs with Kicker"
+task :kick do
+ sh "kicker -e 'rake spec' lib spec"
+end
\ No newline at end of file
Added: DietRB/trunk/lib/irb/context.rb
===================================================================
--- DietRB/trunk/lib/irb/context.rb (rev 0)
+++ DietRB/trunk/lib/irb/context.rb 2010-10-08 10:46:35 UTC (rev 4599)
@@ -0,0 +1,14 @@
+module IRB
+ class Context
+ attr_reader :object, :binding
+
+ def initialize(object)
+ @object = object
+ @binding = object.instance_eval { binding }
+ end
+
+ def evaluate(source)
+ eval(source, @binding)
+ end
+ end
+end
\ No newline at end of file
Added: DietRB/trunk/lib/irb.rb
===================================================================
--- DietRB/trunk/lib/irb.rb (rev 0)
+++ DietRB/trunk/lib/irb.rb 2010-10-08 10:46:35 UTC (rev 4599)
@@ -0,0 +1,2 @@
+require 'irb/context'
+require 'irb/source'
\ No newline at end of file
Added: DietRB/trunk/spec/context_spec.rb
===================================================================
--- DietRB/trunk/spec/context_spec.rb (rev 0)
+++ DietRB/trunk/spec/context_spec.rb 2010-10-08 10:46:35 UTC (rev 4599)
@@ -0,0 +1,25 @@
+require File.expand_path('../spec_helper', __FILE__)
+
+main = self
+
+describe "IRB::Context" do
+ before do
+ @context = IRB::Context.new(main)
+ end
+
+ it "initializes with an object and stores a copy of its binding" do
+ @context.object.should == main
+ eval("self", @context.binding).should == main
+ eval("x = :ok", @context.binding)
+ eval("y = x", @context.binding)
+ eval("y", @context.binding).should == :ok
+ end
+
+ it "does not use the same binding copy of the top level object" do
+ lambda { eval("x", @context.binding) }.should.raise NameError
+ end
+
+ it "evaluates code with the object's binding" do
+ @context.evaluate("self").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:22 UTC (rev 4598)
+++ DietRB/trunk/spec/source_spec.rb 2010-10-08 10:46:35 UTC (rev 4599)
@@ -1,11 +1,5 @@
-require 'rubygems'
-require 'bacon'
+require File.expand_path('../spec_helper', __FILE__)
-ROOT = File.expand_path('../../', __FILE__)
-$:.unshift File.join(ROOT, 'lib')
-
-require 'irb/source'
-
describe "IRB::Source" do
before do
@source = IRB::Source.new
Added: DietRB/trunk/spec/spec_helper.rb
===================================================================
--- DietRB/trunk/spec/spec_helper.rb (rev 0)
+++ DietRB/trunk/spec/spec_helper.rb 2010-10-08 10:46:35 UTC (rev 4599)
@@ -0,0 +1,7 @@
+require 'rubygems'
+require 'bacon'
+
+ROOT = File.expand_path('../../', __FILE__)
+$:.unshift File.join(ROOT, 'lib')
+
+require 'irb'
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101008/446c8735/attachment-0001.html>
More information about the macruby-changes
mailing list