dietrb 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
data/bin/dietrb CHANGED
@@ -1,4 +1,20 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ unless ARGV.empty?
4
+ require 'optparse'
5
+
6
+ OptionParser.new do |opt|
7
+ bin = File.basename($0)
8
+ opt.banner = "Usage: #{bin} [options] [programfile] [arguments]"
9
+ opt.on("-r load-lib", "Loads the given library (same as `ruby -r')") { |lib| require lib }
10
+ opt.on("-d", "Set $DEBUG to true (same as `ruby -d')") { $DEBUG = true }
11
+ opt.on("-I path", "Add path to $LOAD_PATH") { |path| $LOAD_PATH.unshift(path) }
12
+ opt.on("-v", "--version", "Print the version of #{bin}") do
13
+ puts File.read(File.expand_path('../../VERSION', __FILE__))
14
+ exit
15
+ end
16
+ end.parse!(ARGV)
17
+ end
18
+
3
19
  require 'irb'
4
- irb(self)
20
+ irb(self, TOPLEVEL_BINDING)
data/dietrb.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{dietrb}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Eloy Duran"]
data/lib/irb/context.rb CHANGED
@@ -15,9 +15,9 @@ module IRB
15
15
 
16
16
  attr_reader :object, :binding, :line, :source
17
17
 
18
- def initialize(object)
18
+ def initialize(object, explicit_binding = nil)
19
19
  @object = object
20
- @binding = object.instance_eval { binding }
20
+ @binding = explicit_binding || object.instance_eval { binding }
21
21
  @line = 1
22
22
  clear_buffer
23
23
  end
@@ -108,15 +108,15 @@ module IRB
108
108
  end.instance_methods
109
109
  end
110
110
 
111
- def methods_of_object_in_variable(var)
112
- subtype, name = var[VALUE][0..1]
111
+ def methods_of_object_in_variable(path)
112
+ type, name = path[VALUE][0..1]
113
113
 
114
- if var[TYPE] == :top_const_ref
115
- if subtype == :@const && Object.constants.include?(name.to_sym)
114
+ if path[TYPE] == :top_const_ref
115
+ if type == :@const && Object.constants.include?(name.to_sym)
116
116
  evaluate("::#{name}").methods
117
117
  end
118
118
  else
119
- case subtype
119
+ case type
120
120
  when :@ident
121
121
  evaluate(name).methods if local_variables.include?(name)
122
122
  when :@gvar
data/lib/irb.rb CHANGED
@@ -7,8 +7,8 @@ end
7
7
 
8
8
  module Kernel
9
9
  # Creates a new IRB::Context with the given +object+ and runs it.
10
- def irb(object)
11
- IRB::Context.new(object).run
10
+ def irb(object, binding = nil)
11
+ IRB::Context.new(object, binding).run
12
12
  end
13
13
 
14
14
  private :irb
data/spec/context_spec.rb CHANGED
@@ -29,6 +29,12 @@ describe "IRB::Context" do
29
29
  eval("y", @context.binding).should == :ok
30
30
  end
31
31
 
32
+ it "initializes with an object and an explicit binding" do
33
+ context = IRB::Context.new(Object.new, TOPLEVEL_BINDING)
34
+ eval("class InTopLevel; end", context.binding)
35
+ lambda { ::InTopLevel }.should.not.raise NameError
36
+ end
37
+
32
38
  it "initializes with an 'empty' state" do
33
39
  @context.line.should == 1
34
40
  @context.source.should.be.instance_of IRB::Source
@@ -108,7 +114,7 @@ describe "IRB::Context, when evaluating source" do
108
114
  it "prints the exception that occurs" do
109
115
  @context.evaluate("DoesNotExist")
110
116
  printed = @context.instance_variable_get(:@printed)
111
- printed.should.match /^NameError: uninitialized constant DoesNotExist/
117
+ printed.should.match /^NameError:.+DoesNotExist/
112
118
  end
113
119
  end
114
120
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dietrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eloy Duran