Skip to content

Commit

Permalink
Merge pull request #5 from kitaro-tn/dev
Browse files Browse the repository at this point in the history
modify private access
  • Loading branch information
tanish-kr committed Jul 18, 2016
2 parents c811c1d + 4d0b99d commit 038db73
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,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

end
```
Expand Down
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 038db73

Please sign in to comment.