# Re: shortcut to self.class?

**URL:** <https://www.ruby-forum.com/t/re-shortcut-to-self-class/73940>\
**Category:** Ruby\
**Created:** [December 20, 2005, 11:33pm UTC](https://www.ruby-forum.com/t/re-shortcut-to-self-class/73940 "2005-12-20T23:33:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![BergerS\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bc8723/32.png) [@BergerS\_Daniel](https://www.ruby-forum.com/u/BergerS_Daniel)\
**Post date:** [December 20, 2005, 11:33pm UTC](https://www.ruby-forum.com/t/re-shortcut-to-self-class/73940/1 "2005-12-20T23:33:55Z")

</div>

> > 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

---

<div class="post-metadata">

**Author:** ![BergerS\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bc8723/32.png) [@BergerS\_Daniel](https://www.ruby-forum.com/u/BergerS_Daniel)\
**Post date:** [December 20, 2005, 11:49pm UTC](https://www.ruby-forum.com/t/re-shortcut-to-self-class/73940/2 "2005-12-20T23:49:08Z")

</div>

> > 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

---

<div class="post-metadata">

**Author:** ![BergerS\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bc8723/32.png) [@BergerS\_Daniel](https://www.ruby-forum.com/u/BergerS_Daniel)\
**Post date:** [December 21, 2005, 1:25am UTC](https://www.ruby-forum.com/t/re-shortcut-to-self-class/73940/3 "2005-12-21T01:25:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![BergerS\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bc8723/32.png) [@BergerS\_Daniel](https://www.ruby-forum.com/u/BergerS_Daniel)\
**Post date:** [December 21, 2005, 5:50pm UTC](https://www.ruby-forum.com/t/re-shortcut-to-self-class/73940/4 "2005-12-21T17:50:16Z")

</div>

On 20/12/05, Berger, Daniel [removed\_email\_address@domain.invalid](mailto: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

---

<div class="post-metadata">

**Author:** ![BergerS\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bc8723/32.png) [@BergerS\_Daniel](https://www.ruby-forum.com/u/BergerS_Daniel)\
**Post date:** [December 21, 2005, 6:08pm UTC](https://www.ruby-forum.com/t/re-shortcut-to-self-class/73940/5 "2005-12-21T18:08:23Z")

</div>

On Thu, 22 Dec 2005, Austin Z. wrote:

> On 20/12/05, Berger, Daniel [removed\_email\_address@domain.invalid](mailto: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

---

<div class="post-metadata">

**Author:** ![BergerS\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bc8723/32.png) [@BergerS\_Daniel](https://www.ruby-forum.com/u/BergerS_Daniel)\
**Post date:** [December 21, 2005, 1:43am UTC](https://www.ruby-forum.com/t/re-shortcut-to-self-class/73940/6 "2005-12-21T01:43:49Z")

</div>

On Wed, 21 Dec 2005 00:22:40 -0000, MenTaLguY [removed\_email\_address@domain.invalid](mailto: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).
