Skip to content

Commit

Permalink
Merge 72f6363 into c811c1d
Browse files Browse the repository at this point in the history
  • Loading branch information
tanish-kr committed Jul 18, 2016
2 parents c811c1d + 72f6363 commit 9ff8803
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions lib/as_namespace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@ module ClassMethod

##
# @param [Module] module_obj
# @param [Object] alias_val
def as_namespace(module_obj:, alias_val:)
# @param [String] alias_val
def as_namespace(module_obj, alias_val)
@module_obj = module_obj
@alias_val = alias_val
if (alias_val =~ /^[[:upper:]]/).nil?
self.class_eval <<-EOS, __FILE__, __LINE__ + 1
def #{alias_val}
private def #{alias_val}
#{module_obj}
end
EOS
else
self.const_set(alias_val, module_obj)
self.private_constant(alias_val)
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/as_namespace_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

it 'is abbreviated name' do
test_class = TestClass
expect(test_class.instance_methods(false)).to include(:grand)
expect(test_class.instance_methods(false)).not_to include(:grand)
expect(test_class.const_defined?(:CHILD)).to be true
expect(test_class.new.grandson).to eq("Grandson")
expect(test_class.new.child).to eq("Child")
Expand Down
4 changes: 2 additions & 2 deletions spec/support/sample_namespace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class TestClass

include AsNamespace

as_namespace module_obj: Parent::Child::Grandson, alias_val: :grand
as_namespace module_obj: Parent::Child, alias_val: :CHILD
as_namespace Parent::Child::Grandson, :grand
as_namespace Parent::Child, :CHILD

attr_reader :grandson, :child

Expand Down

0 comments on commit 9ff8803

Please sign in to comment.