Project

General

Profile

Bug #7271

Refinement doesn't seem lexical

Added by Koichi Sasada over 3 years ago. Updated about 3 years ago.

Status:
Closed
Priority:
Normal
Assignee:
ruby -v:
ruby 2.0.0dev (2012-11-01 trunk 37404) [i386-mswin32_100]
Backport:
2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
[ruby-core:48820]

Description

C_User#y is refined. Is that intentional?

class C
def foo
p :C_foo
end
end

module RefineC
refine C do
def foo
p :RefineC_foo
super
end
end
end

class C_User
using RefineC
def x
C.new.foo
end
end

class C_User
def y
C.new.foo
end
end

C_User.new.x
C_User.new.y

#=>
:RefineC_foo
:C_foo
:RefineC_foo
:C_foo


Related issues

Related to Ruby trunk - Feature #4085: Refinements and nested methods Closed 11/24/2010

History

#1 [ruby-core:48871] Updated by Shugo Maeda over 3 years ago

ko1 (Koichi Sasada) wrote:

C_User#y is refined. Is that intentional?

Yes, it's intentional. Refinements are activated when C_User is reopend.

I'm not sure whether is'a good idea or not, but if C_User.module_eval is affected by refinements, it seems natural reopened definitions of C_User are also affected.

#2 [ruby-core:48888] Updated by Koichi Sasada over 3 years ago

(2012/11/05 11:57), shugo (Shugo Maeda) wrote:

Yes, it's intentional. Refinements are activated when C_User is reopend.

I'm not sure whether is'a good idea or not, but if C_User.module_eval is affected by refinements, it seems natural reopened definitions of C_User are also affected.

I can't understand that refinement is "lexical" or not.

If it affected after re-open, then it is not "lexical".
If the location of `using' affect the result, then it seems "lexical".
( [ruby-trunk - Bug #7269])

--
// SASADA Koichi at atdot dot net

#3 [ruby-core:48890] Updated by Shugo Maeda over 3 years ago

ko1 (Koichi Sasada) wrote:

(2012/11/05 11:57), shugo (Shugo Maeda) wrote:

Yes, it's intentional. Refinements are activated when C_User is reopend.

I'm not sure whether is'a good idea or not, but if C_User.module_eval is affected by refinements, it seems natural reopened definitions of C_User are also affected.

I can't understand that refinement is "lexical" or not.

If it affected after re-open, then it is not "lexical".
If the location of `using' affect the result, then it seems "lexical".
( [ruby-trunk - Bug #7269])

I may have confused you by the word lexical, but I used the word lexical in the sense that refinements have no local rebinding. I'm not sure whether refinements should be literally lexical or not.

I guess if refinements are literally lexical it's good for performance, but how module_eval (or an alternative to apply refinements to a given block) should behave?

#4 [ruby-core:50858] Updated by Shugo Maeda about 3 years ago

  • Status changed from Assigned to Closed

Refinements are not activated by reopen now, so I close this ticket.

Also available in: Atom PDF