Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rubinius/rubinius
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 533da7eadbf6
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ce1791f52e5f
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Jul 18, 2015

  1. Allow passing strings to #{private,public}_constant

    The maintained constants table is dealing with symbols but these methods
    can take strings as arguments ; it's pretty common to pass `class.name`
    as an argument.
    robin850 committed Jul 18, 2015
    Copy the full SHA
    4393d79 View commit details
  2. Copy the full SHA
    ce1791f View commit details
Showing with 20 additions and 0 deletions.
  1. +2 −0 kernel/common/module.rb
  2. +8 −0 spec/ruby/core/module/private_constant_spec.rb
  3. +10 −0 spec/ruby/core/module/public_constant_spec.rb
2 changes: 2 additions & 0 deletions kernel/common/module.rb
Original file line number Diff line number Diff line change
@@ -130,6 +130,7 @@ def constants(all=undefined)
end

def private_constant(*names)
names = names.map(&:to_sym)
unknown_constants = names - @constant_table.keys
if unknown_constants.size > 0
raise NameError, "#{unknown_constants.size > 1 ? 'Constants' : 'Constant'} #{unknown_constants.map{|e| "#{name}::#{e}"}.join(', ')} undefined"
@@ -141,6 +142,7 @@ def private_constant(*names)
end

def public_constant(*names)
names = names.map(&:to_sym)
unknown_constants = names - @constant_table.keys
if unknown_constants.size > 0
raise NameError, "#{unknown_constants.size > 1 ? 'Constants' : 'Constant'} #{unknown_constants.map{|e| "#{name}::#{e}"}.join(', ')} undefined"
8 changes: 8 additions & 0 deletions spec/ruby/core/module/private_constant_spec.rb
Original file line number Diff line number Diff line change
@@ -11,6 +11,14 @@
end.should raise_error(NameError)
end

it "accepts strings as constant names" do
cls = Class.new
cls.const_set :Foo, true
cls.send :private_constant, "Foo"

lambda { cls::Foo }.should raise_error(NameError)
end

ruby_bug "[ruby-list:48559]", "1.9.3" do
it "accepts multiple names" do
mod = Module.new
10 changes: 10 additions & 0 deletions spec/ruby/core/module/public_constant_spec.rb
Original file line number Diff line number Diff line change
@@ -11,6 +11,16 @@
end.should raise_error(NameError)
end

it "accepts strings as constant names" do
cls = Class.new
cls.const_set :Foo, true

cls.send :private_constant, :Foo
cls.send :public_constant, "Foo"

cls::Foo.should == true
end

# [ruby-list:48558]
it "accepts multiple names" do
mod = Module.new