Forum: Ruby Re: shortcut to self.class ?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Berger, Daniel (Guest)
on 2005-12-21 00:33
(Received via mailing list)
> > Yeah, it may be awhile before I have enough time to learn ruby
> for the weird stuff (e.g. heredocs), but most of the edge
> cases are just edge cases and I think I can deal with those.
>
> -mental

Then ditch heredocs.  I can't think of a case where I desperately needed
a heredoc over, say, %q{}.

- Dan
gabriele renzi (Guest)
on 2005-12-21 00:49
(Received via mailing list)
>>As far as Ruby goes, I'm definitely going to need your help
>>for the weird stuff (e.g. heredocs), but most of the edge
>>cases are just edge cases and I think I can deal with those.
>>
>>-mental
>
>
> Then ditch heredocs.  I can't think of a case where I desperately needed
> a heredoc over, say, %q{}.

+1
especially for stuff like multiple here docs headers in one line:
a=<<EoA, b= <<EoB
fofofo
EoA
blabla
EoB
MenTaLguY (Guest)
on 2005-12-21 02:25
(Received via mailing list)
On Wed, 2005-12-21 at 07:32 +0900, Berger, Daniel wrote:
> Then ditch heredocs.  I can't think of a case where I desperately needed
> a heredoc over, say, %q{}.

That's the point of doing a subset grammar to begin with -- we can leave
all the weird stuff like heredocs until last.

But heredocs are a part of Ruby's grammar, so we are going to have to
accommodate them eventually.  It's doable, just funky.

-mental
Ross B. (Guest)
on 2005-12-21 02:43
(Received via mailing list)
On Wed, 21 Dec 2005 00:22:40 -0000, MenTaLguY 
<removed_email_address@domain.invalid> wrote:

> But heredocs are a part of Ruby's grammar, so we are going to have to
> accommodate them eventually.  It's doable, just funky.
>

Just to chime in, I have to agree on that - AFAIU the reason for wanting
rid of yacc is because it limits the syntax, so I think it's important
that the effort to find a replacement aim to (eventually) support
everything that's currently supported. Otherwise, surely it's a case of
better the devil you know...

(That said though, I've used ANTLR a little bit in Java and I'm certain
that if anything can do it, ANTLR can).
Austin Z. (Guest)
on 2005-12-21 18:50
(Received via mailing list)
On 20/12/05, Berger, Daniel <removed_email_address@domain.invalid> wrote:
> Then ditch heredocs.  I can't think of a case where I desperately needed
> a heredoc over, say, %q{}.

I use heredocs often. A grammar that doesn't support heredocs won't be
a Ruby grammar.

-austin
unknown (Guest)
on 2005-12-21 19:08
(Received via mailing list)
On Thu, 22 Dec 2005, Austin Z. wrote:

> On 20/12/05, Berger, Daniel <removed_email_address@domain.invalid> wrote:
>> Then ditch heredocs.  I can't think of a case where I desperately needed
>> a heredoc over, say, %q{}.
>
> I use heredocs often. A grammar that doesn't support heredocs won't be
> a Ruby grammar.

agreed.  it's extremely difficult to do any serious metaprogramming
without
them.  here is a snippet from something i was working on yesterday:

       def xx_config_attr attr, default = nil

         module_eval <<-code
           module InstanceMethods
             def #{ attr } *argv
               if argv.empty?
                 if defined? @#{ attr }
                   return @#{ attr }
                 else
                   return(self.class.send("#{ attr }"))
                 end
               else
                 return(send("#{ attr }=", argv.shift))
               end
               nil
             end

             def #{ attr }= value
               @#{ attr } = value
             end
           end

           module ClassMethods
             def #{ attr } *argv
               if argv.empty?
                 if defined? @#{ attr }
                   return @#{ attr }
                 else
                   ancestors.each do |a|
                     next if self == a
                     if a.respond_to? "#{ attr }"
                       return(a.send("#{ attr }"))
                     end
                   end
                 end
               else
                 return(send("#{ attr }=", argv.shift))
               end
               nil
             end

             def #{ attr }= value
               @#{ attr } = value
             end
           end

           def self::#{ attr } *argv
             if argv.empty?
               if defined? @#{ attr }
                 return @#{ attr }
               end
             else
               return(send("#{ attr }=", argv.shift))
             end
             nil
           end

           def self::#{ attr }= value
             @#{ attr } = value
           end
         code

         send "#{ attr }=", default
       end

this kind of stuff is extremely difficult to code if you are limited to
symbols like {,(,{, etc to delimit the string.  this is true anytime
your
string contains arbitrary code.  heredocs make it possible.

regards.

-a
This topic is locked and can not be replied to.