--e89a8ff2561020fa0b04d044c75b
Content-Type: text/plain; charset=ISO-8859-1

Not all column names can be represented as method names. Or can they?

Even if they could I don't like this approach. Look, I currently maintain
an application that has some parts written in Grails, others in plain Java
and others in Rails. I can do things even more advanced than what you
suggested in Grails thanks to some features in Groovy.

But the problem begins when you have some local variable (or method) name
that happens to be the same as the column.

In such cases the DSL approach doesn't really help and may yield to
unexpected results (from a user POV)
Em 07/12/2012 11:43, "trans (Thomas Sawyer)" <transfire / gmail.com> escreveu:

>
> Issue #4085 has been updated by trans (Thomas Sawyer).
>
>
> in
> @rosenfeld I think the point was that a better designed API could do:
>
>   records  B[:some_table].
>     where{some_column.like '%A'}.
>     except{other_column < 3}.
>     where{another_one.in [3, 6]}.
>     order{sort_column.desc}
>
> ▀┼
> ----------------------------------------
> Feature #4085: Refinements and nested methods
> https://bugs.ruby-lang.org/issues/4085#change-34506
>
> Author: shugo (Shugo Maeda)
> Status: Assigned
> Priority: Normal
> Assignee: matz (Yukihiro Matsumoto)
> Category: core
> Target version: 2.0.0
>
>
> ą╗gin
>  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  oo.new
>    f.foo #(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  oo.new
>      foo.bar  # FooExt#bar
>      foo.baz  # 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  #(1/2)
>    end
>
>    class Bar < Foo
>      # MathN is enabled in a subclass definition.
>      p 1 / 2  #(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  #(1/2)
>    end
>    A.module_eval do
>      p 1 / 2  #(1/2)
>    end
>    B.class_eval do
>      p 1 / 2  #(1/2)
>    end
>    B.new.instance_eval do
>      p 1 / 2  #(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 method.
>
>    def foo
>      def bar
>        puts "bar"
>      end
>      bar
>    end
>    foo  #bar
>    bar  #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  elf.class
>      m  odule.new {
>        refine klass do
>          def bar
>            puts "bar"
>          end
>        end
>      }
>      using m
>      bar
>    end
>    foo  #bar
>    bar  #NoMethodError
>
>  The attached patch is based on SVN trunk r29837.
> ▀┼
>
>
>
> --
> http://bugs.ruby-lang.org/
>
>

--e89a8ff2561020fa0b04d044c75b
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<p>Not all column names can be represented as method names. Or can they?</p>
<p>Even if they could I don&#39;t like this approach. Look, I currently maintain an application that has some parts written in Grails, others in plainava and others in Rails. I can do things even more advanced than what youuggested in Grails thanks to some features in Groovy.</p>

<p>But the problem begins when you have some local variable (or method) name that happens to be the same as the column.</p>
<p>In such cases the DSL approach doesn&#39;t really help and may yield to unexpected results (from a user POV)</p>
<div class="gmail_quote">Em 07/12/2012 11:43, &quot;trans (Thomas Sawyer)&quot; &lt;transfire / gmail.com&gt; escreveu:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Issue #4085 has been updated by trans (Thomas Sawyer).<br>
<br>
<br>
=begin<br>
@rosenfeld I think the point was that a better designed API could do:<br>
<br>
records = DB[:some_table].<br>
where{some_column.like &#39;%A&#39;}.<br>
except{other_column &lt; 3}.<br>
where{<a href="http://another_one.in" target="_blank">another_one.in</a> [3, 6]}.<br>
order{sort_column.desc}<br>
<br>
=end<br>
----------------------------------------<br>
Feature #4085: Refinements and nested methods<br>
<a href="https://bugs.ruby-lang.org/issues/4085#change-34506" target="_blank">https://bugs.ruby-lang.org/issues/4085#change-34506</a><br>
<br>
Author: shugo (Shugo Maeda)<br>
Status: Assigned<br>
Priority: Normal<br>
Assignee: matz (Yukihiro Matsumoto)<br>
Category: core<br>
Target version: 2.0.0<br>
<br>
<br>
=begin<br>
s I said at RubyConf 2010, I&#39;d like to propose a new features called<br>
quot;Refinements.&quot;<br>
<br>
efinements are similar to Classboxes. owever, Refinements doesn&#39;t<br>
upport local rebinding as mentioned later. n this sense,<br>
efinements might be more similar to selector namespaces, but I&#39;m not<br>
ure because I have never seen any implementation of selector<br>
amespaces.<br>
<br>
n Refinements, a Ruby module is used as a namespace (or classbox) for<br>
lass extensions. uch class extensions are called refinements. or<br>
xample, the following module refines Fixnum.<br>
<br>
odule MathN<br>
efine Fixnum do<br>
ef /(other) quo(other) end<br>
nd<br>
nd<br>
<br>
odule#refine(klass) takes one argument, which is a class to be<br>
xtended. odule#refine also takes a block, where additional or<br>
verriding methods of klass can be defined. n this example, MathN<br>
efines Fixnum so that 1 / 2 returns a rational number (1/2) instead<br>
f an integer 0.<br>
<br>
his refinement can be enabled by the method using.<br>
<br>
lass Foo<br>
sing MathN<br>
<br>
ef foo<br>
 1 / 2<br>
nd<br>
nd<br>
<br>
 = Foo.new<br>
.foo #=&gt; (1/2)<br>
 1 / 2<br>
<br>
n this example, the refinement in MathN is enabled in the definition<br>
f Foo. he effective scope of the refinement is the innermost class,<br>
odule, or method where using is called; however the refinement is not<br>
nabled before the call of using. f there is no such class, module,<br>
r method, then the effective scope is the file where using is called.<br>
ote that refinements are pseudo-lexically scoped. or example,<br>
oo.baz prints not &quot;FooExt#bar&quot; but &quot;Foo#bar&quot; in theollowing code:<br>
<br>
lass Foo<br>
ef bar<br>
uts &quot;Foo#bar&quot;<br>
nd<br>
<br>
ef baz<br>
ar<br>
nd<br>
nd<br>
<br>
odule FooExt<br>
efine Foo do<br>
ef bar<br>
uts &quot;FooExt#bar&quot;<br>
nd<br>
nd<br>
nd<br>
<br>
odule Quux<br>
sing FooExt<br>
<br>
oo = Foo.new<br>
oo.bar  =&gt; FooExt#bar<br>
oo.baz  =&gt; Foo#bar<br>
nd<br>
<br>
efinements are also enabled in reopened definitions of classes using<br>
efinements and definitions of their subclasses, so they are<br>
pseudo*-lexically scoped.<br>
<br>
lass Foo<br>
sing MathN<br>
nd<br>
<br>
lass Foo<br>
 MathN is enabled in a reopened definition.<br>
 1 / 2 =&gt; (1/2)<br>
nd<br>
<br>
lass Bar &lt; Foo<br>
 MathN is enabled in a subclass definition.<br>
 1 / 2 =&gt; (1/2)<br>
nd<br>
<br>
f a module or class is using refinements, they are enabled in<br>
odule_eval, class_eval, and instance_eval if the receiver is the<br>
lass or module, or an instance of the class.<br>
<br>
odule A<br>
sing MathN<br>
nd<br>
lass B<br>
sing MathN<br>
nd<br>
athN.module_eval do<br>
 1 / 2 =&gt; (1/2)<br>
nd<br>
.module_eval do<br>
 1 / 2 =&gt; (1/2)<br>
nd<br>
.class_eval do<br>
 1 / 2 =&gt; (1/2)<br>
nd<br>
.new.instance_eval do<br>
 1 / 2 =&gt; (1/2)<br>
nd<br>
<br>
esides refinements, I&#39;d like to propose new behavior of nested methods.<br>
urrently, the scope of a nested method is not closed in the outer method.<br>
<br>
ef foo<br>
ef bar<br>
uts &quot;bar&quot;<br>
nd<br>
ar<br>
nd<br>
oo =&gt; bar<br>
ar =&gt; bar<br>
<br>
n Ruby, there are no functions, but only methods. o there are no<br>
ight places where nested methods are defined. owever, if<br>
efinements are introduced, a refinement enabled only in the outer<br>
ethod would be the right place. or example, the above code is<br>
lmost equivalent to the following code:<br>
<br>
ef foo<br>
lass = self.class<br>
 = Module.new {<br>
efine klass do<br>
ef bar<br>
uts &quot;bar&quot;<br>
nd<br>
nd<br>
<br>
sing m<br>
ar<br>
nd<br>
oo =&gt; bar<br>
ar =&gt; NoMethodError<br>
<br>
he attached patch is based on SVN trunk r29837.<br>
=end<br>
<br>
<br>
<br>
--<br>
<a href="http://bugs.ruby-lang.org/" target="_blank">http://bugs.ruby-lang.org/</a><br>
<br>
</blockquote></div>

--e89a8ff2561020fa0b04d044c75b--