[#48745] [ruby-trunk - Bug #7267][Open] Dir.glob on Mac OS X returns unexpected string encodings for unicode file names — "kennygrant (Kenny Grant)" <kennygrant@...>

17 messages 2012/11/02

[#48773] [ruby-trunk - Bug #7269][Open] Refinement doesn't work if using locate after method — "ko1 (Koichi Sasada)" <redmine@...>

12 messages 2012/11/03

[#48847] [ruby-trunk - Bug #7274][Open] UnboundMethods should be bindable to any object that is_a?(owner of the UnboundMethod) — "rits (First Last)" <redmine@...>

21 messages 2012/11/04

[#48854] [ruby-trunk - Bug #7276][Open] TestFile#test_utime failure — "jonforums (Jon Forums)" <redmine@...>

14 messages 2012/11/04

[#48988] [ruby-trunk - Feature #7292][Open] Enumerable#to_h — "marcandre (Marc-Andre Lafortune)" <ruby-core@...>

40 messages 2012/11/06

[#48997] [ruby-trunk - Feature #7297][Open] map_to alias for each_with_object — "nathan.f77 (Nathan Broadbent)" <nathan.f77@...>

19 messages 2012/11/06

[#49001] [ruby-trunk - Bug #7298][Open] Behavior of Enumerator.new different between 1.9.3 and 2.0.0 — "ayumin (Ayumu AIZAWA)" <ayumu.aizawa@...>

12 messages 2012/11/06

[#49018] [ruby-trunk - Feature #7299][Open] Ruby should not completely ignore blocks. — "marcandre (Marc-Andre Lafortune)" <ruby-core@...>

13 messages 2012/11/07

[#49044] [ruby-trunk - Bug #7304][Open] Random test failures around test_autoclose_true_closed_by_finalizer — "luislavena (Luis Lavena)" <luislavena@...>

11 messages 2012/11/07

[#49196] [ruby-trunk - Feature #7322][Open] Add a new operator name #>< for bit-wise "exclusive or" — "alexeymuranov (Alexey Muranov)" <redmine@...>

18 messages 2012/11/10

[#49211] [ruby-trunk - Feature #7328][Open] Move ** operator precedence under unary + and - — "boris_stitnicky (Boris Stitnicky)" <boris@...>

20 messages 2012/11/11

[#49229] [ruby-trunk - Bug #7331][Open] Set the precedence of unary `-` equal to the precedence `-`, same for `+` — "alexeymuranov (Alexey Muranov)" <redmine@...>

17 messages 2012/11/11

[#49256] [ruby-trunk - Feature #7336][Open] Flexiable OPerator Precedence — "trans (Thomas Sawyer)" <transfire@...>

18 messages 2012/11/12

[#49354] review open pull requests on github — Zachary Scott <zachary@...>

Could we get a review on any open pull requests on github before the

12 messages 2012/11/15
[#49355] Re: review open pull requests on github — "NARUSE, Yui" <naruse@...> 2012/11/15

2012/11/15 Zachary Scott <[email protected]>:

[#49356] Re: review open pull requests on github — Zachary Scott <zachary@...> 2012/11/15

Ok, I was hoping one of the maintainers might want to.

[#49451] [ruby-trunk - Bug #7374][Open] File.expand_path resolving to first file/dir instead of absolute path — mdube@... (Martin Dubé) <mdube@...>

12 messages 2012/11/16

[#49463] [ruby-trunk - Feature #7375][Open] embedding libyaml in psych for Ruby 2.0 — "tenderlovemaking (Aaron Patterson)" <aaron@...>

21 messages 2012/11/16
[#49494] [ruby-trunk - Feature #7375] embedding libyaml in psych for Ruby 2.0 — "vo.x (Vit Ondruch)" <v.ondruch@...> 2012/11/17

[#49467] [ruby-trunk - Feature #7377][Open] #indetical? as an alias for #equal? — "aef (Alexander E. Fischer)" <aef@...>

13 messages 2012/11/17

[#49558] [ruby-trunk - Bug #7395][Open] Negative numbers can't be primes by definition — "zzak (Zachary Scott)" <zachary@...>

10 messages 2012/11/19

[#49566] [ruby-trunk - Feature #7400][Open] Incorporate OpenSSL tests from JRuby. — "zzak (Zachary Scott)" <zachary@...>

11 messages 2012/11/19

[#49770] [ruby-trunk - Feature #7414][Open] Now that const_get supports "Foo::Bar" syntax, so should const_defined?. — "robertgleeson (Robert Gleeson)" <rob@...>

9 messages 2012/11/20

[#49950] [ruby-trunk - Feature #7427][Assigned] Update Rubygems — "mame (Yusuke Endoh)" <mame@...>

17 messages 2012/11/24

[#50043] [ruby-trunk - Bug #7429][Open] Provide options for core collections to customize behavior — "headius (Charles Nutter)" <headius@...>

10 messages 2012/11/24

[#50092] [ruby-trunk - Feature #7434][Open] Allow caller_locations and backtrace_locations to receive negative params — "sam.saffron (Sam Saffron)" <sam.saffron@...>

21 messages 2012/11/25

[#50094] [ruby-trunk - Bug #7436][Open] Allow for a "granularity" flag for backtrace_locations — "sam.saffron (Sam Saffron)" <sam.saffron@...>

11 messages 2012/11/25

[#50207] [ruby-trunk - Bug #7445][Open] strptime('%s %z') doesn't work — "felipec (Felipe Contreras)" <felipe.contreras@...>

19 messages 2012/11/27

[#50424] [ruby-trunk - Bug #7485][Open] ruby cannot build on mingw32 due to missing __sync_val_compare_and_swap — "drbrain (Eric Hodel)" <[email protected]>

15 messages 2012/11/30

[#50429] [ruby-trunk - Feature #7487][Open] Cutting through the issues with Refinements — "trans (Thomas Sawyer)" <transfire@...>

13 messages 2012/11/30

[ruby-core:48828] Re: [ruby-trunk - Feature #4085] Refinements and nested methods

From: Akira Matsuda <ronnie@...>
Date: 2012-11-03 23:42:11 UTC
List: ruby-core #48828
Playing with refinements after talking with Charlie, I found
refinements are not very much attractive feature without module_eval.
I think I do understand the down sides Charlie described.
And I'm sure people will abuse this refinements + module_eval
technique if they are allowed to, because it just looks cool.

So, I guess the point is whether to allow users to write code like this or =
not;

module A
  refine Fixnum do
    def +(o); self * o; end
  end
end

class C
  def foo(&b)
    Module.new { using A }.module_eval &b
  end
end

C.new.foo { p 2 + 3 }
#=3D> 6

My personal opinion is, still, as a library / framework author, I'm
sort of anticipating to see such future that people are abusing this.
People may find good practices to control the power somehow, then it
might definitely push the DSL culture up to the absolute next level,
which must be totally exciting.


On Sat, Nov 3, 2012 at 2:57 PM, SASADA Koichi <[email protected]> wrote:
> I have another implementation idea, using "prepend".
> I also try it next week.
> (I can't explain this idea in English, so I will write code).
>
>
> (2012/11/03 14:33), headius (Charles Nutter) wrote:
>>
>> Issue #4085 has been updated by headius (Charles Nutter).
>>
>>
>> Discussed refinements a bit with Matz + ko1 plus a_matsuda and others at=
 lunch...here's summary.
>>
>> The using method currently touches cref, making it largely scoped like c=
onstants. If refinement lookup at a call site proceeds the same way, it wou=
ld simplify things in my head quite a bit.
>>
>> Benefits to having refinement lookup follow cref:
>>
>> * No frame field is necessary
>> * Easier-to-understand behavior, since the lookup would mimic constant l=
ookup (lexical then hierarchical)
>>
>> There are down sides:
>>
>> * module_eval cases would not be possible, since like constant lookup re=
finements cannot be injected into a scope after the fact
>> * It is not purely lexical, as I had hoped. However, I recognize that ha=
ving to "using" in every scope where you want refinements to be active woul=
d be painful.
>> * It may need a global invalidation guard, like constants. It may not, t=
hough, since refinements are applied only once, at definition time; so afte=
r caching once we may have everything we need for future invalidation.
>>
>> One concern of mine was avoiding refinement checks at all call sites. Wi=
th cref-based "using" there's no way to determine at parse time which metho=
ds might need refinements. We can determine it at definition time, but the =
AST is already parsed at that point, so we'd have to rewrite it to have "re=
fined calls" instead of normal calls, or something similar. This also impac=
ts JRuby's ahead-of-time compilation support...we do not have the luxury of=
 running the target code for precompilation, so we can't see if there are r=
efinements active.
>>
>> For normal runtime jitted code, rewriting the AST or adding a "refined" =
flag to call nodes may be feasible. Calls can then use a refined call site =
only in the cases where refinements are active.
>>
>> For AOT mode, I think the best I can do is to have a flag on the call si=
tes to indicate if refinements are active. If there's no refinements for th=
e first call, there will be no refinements for any future calls, and we can=
 turn that logic off. It would still require that boolean check every time.=
..I don't see a way to eliminate that. (Side note: on invokedynamic, that b=
oolean check would end up free, so it may not be a huge deal long term).
>>
>> I will attempt to prototype pure cref-based refinement lookup over the n=
ext week.
>> ----------------------------------------
>> Feature #4085: Refinements and nested methods
>> https://bugs.ruby-lang.org/issues/4085#change-32309
>>
>> Author: shugo (Shugo Maeda)
>> Status: Assigned
>> Priority: Normal
>> Assignee: matz (Yukihiro Matsumoto)
>> Category: core
>> Target version: 2.0.0
>>
>>
>> =3Dbegin
>>  As I said at RubyConf 2010, I'd like to propose a new features called
>>  "Refinements."
>>
>>  Refinements are similar to Classboxes.  However, Refinements doesn't
>>  support local rebinding as mentioned later.  In this sense,
>>  Refinements might be more similar to selector namespaces, but I'm not
>>  sure because I have never seen any implementation of selector
>>  namespaces.
>>
>>  In Refinements, a Ruby module is used as a namespace (or classbox) for
>>  class extensions.  Such class extensions are called refinements.  For
>>  example, the following module refines Fixnum.
>>
>>    module MathN
>>      refine Fixnum do
>>        def /(other) quo(other) end
>>      end
>>    end
>>
>>  Module#refine(klass) takes one argument, which is a class to be
>>  extended.  Module#refine also takes a block, where additional or
>>  overriding methods of klass can be defined.  In this example, MathN
>>  refines Fixnum so that 1 / 2 returns a rational number (1/2) instead
>>  of an integer 0.
>>
>>  This refinement can be enabled by the method using.
>>
>>    class Foo
>>      using MathN
>>
>>      def foo
>>        p 1 / 2
>>      end
>>    end
>>
>>    f =3D Foo.new
>>    f.foo #=3D> (1/2)
>>    p 1 / 2
>>
>>  In this example, the refinement in MathN is enabled in the definition
>>  of Foo.  The effective scope of the refinement is the innermost class,
>>  module, or method where using is called; however the refinement is not
>>  enabled before the call of using.  If there is no such class, module,
>>  or method, then the effective scope is the file where using is called.
>>  Note that refinements are pseudo-lexically scoped.  For example,
>>  foo.baz prints not "FooExt#bar" but "Foo#bar" in the following code:
>>
>>    class Foo
>>      def bar
>>        puts "Foo#bar"
>>      end
>>
>>      def baz
>>        bar
>>      end
>>    end
>>
>>    module FooExt
>>      refine Foo do
>>        def bar
>>          puts "FooExt#bar"
>>        end
>>      end
>>    end
>>
>>    module Quux
>>      using FooExt
>>
>>      foo =3D Foo.new
>>      foo.bar  # =3D> FooExt#bar
>>      foo.baz  # =3D> Foo#bar
>>    end
>>
>>  Refinements are also enabled in reopened definitions of classes using
>>  refinements and definitions of their subclasses, so they are
>>  *pseudo*-lexically scoped.
>>
>>    class Foo
>>      using MathN
>>    end
>>
>>    class Foo
>>      # MathN is enabled in a reopened definition.
>>      p 1 / 2  #=3D> (1/2)
>>    end
>>
>>    class Bar < Foo
>>      # MathN is enabled in a subclass definition.
>>      p 1 / 2  #=3D> (1/2)
>>    end
>>
>>  If a module or class is using refinements, they are enabled in
>>  module_eval, class_eval, and instance_eval if the receiver is the
>>  class or module, or an instance of the class.
>>
>>    module A
>>      using MathN
>>    end
>>    class B
>>      using MathN
>>    end
>>    MathN.module_eval do
>>      p 1 / 2  #=3D> (1/2)
>>    end
>>    A.module_eval do
>>      p 1 / 2  #=3D> (1/2)
>>    end
>>    B.class_eval do
>>      p 1 / 2  #=3D> (1/2)
>>    end
>>    B.new.instance_eval do
>>      p 1 / 2  #=3D> (1/2)
>>    end
>>
>>  Besides refinements, I'd like to propose new behavior of nested methods=
.
>>  Currently, the scope of a nested method is not closed in the outer meth=
od.
>>
>>    def foo
>>      def bar
>>        puts "bar"
>>      end
>>      bar
>>    end
>>    foo  #=3D> bar
>>    bar  #=3D> bar
>>
>>  In Ruby, there are no functions, but only methods.  So there are no
>>  right places where nested methods are defined.  However, if
>>  refinements are introduced, a refinement enabled only in the outer
>>  method would be the right place.  For example, the above code is
>>  almost equivalent to the following code:
>>
>>    def foo
>>      klass =3D self.class
>>      m =3D Module.new {
>>        refine klass do
>>          def bar
>>            puts "bar"
>>          end
>>        end
>>      }
>>      using m
>>      bar
>>    end
>>    foo  #=3D> bar
>>    bar  #=3D> NoMethodError
>>
>>  The attached patch is based on SVN trunk r29837.
>> =3Dend
>>
>>
>>
>
>
> --
> // SASADA Koichi at atdot dot net
>



--=20
Akira Matsuda<[email protected]>

In This Thread