[Code] Creating attr like methods

[Code] Creating attr like methods

Postby thomthom » Thu Sep 15, 2011 1:22 pm

I have a set of classes where I'd like to use attr like syntax to define some properties for each class. Each of these classes inherit from a base class. I was wondering if it was possible to define your own attr like syntax?

Code: Select all
class Hello < MyBaseClass
  foo
( :lorem, :ipsum )
end





The simple solution:
Code: Select all
class MyBaseClass
  private 
# Not required, but I like to scope'em.
  def self.foo( *args )
    # Do magic stuff!
  end
end

class Hello 
< MyBaseClass
  foo
( :lorem, :ipsum )
end



It was pretty much what I had tried before posting the question, but I'd forgotten to add self. ... :oops:
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: Creating attr like methods

Postby thomthom » Thu Sep 15, 2011 1:52 pm

0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: Creating attr like methods

Postby Dan Rathbun » Thu Sep 15, 2011 5:02 pm

thomthom wrote:I was wondering if it was possible to define your own attr like syntax?

I really think they missed an attr-like method for modules and classes that creates and inits class @@ vars.
0
    I'm not here much anymore. But a PM will fire email notifications.
    User avatar
    Dan Rathbun 
    PluginStore Author
    PluginStore Author
     

    Re: Creating attr like methods

    Postby thomthom » Thu Sep 15, 2011 5:04 pm

    Dan Rathbun wrote:
    thomthom wrote:I was wondering if it was possible to define your own attr like syntax?

    I really think they missed an attr-like method for modules and classes that creates and inits class @@ vars.

    Aye!
    0
    Thomas Thomassen — SketchUp Monkey & Coding addict
    List of my plugins and link to the CookieWare fund
    User avatar
    thomthom 
    PluginStore Author
    PluginStore Author
     

    Re: Creating attr like methods

    Postby tbd » Thu Sep 15, 2011 5:12 pm

    maybe add an example in this thread (maybe original post) to have it for further searches. thanks.
    0
    SketchUp Ruby Consultant | Podium 1.x developer
    http://plugins.ro
    User avatar
    tbd 
     

    Re: Creating attr like methods

    Postby thomthom » Thu Sep 15, 2011 5:44 pm

    TBD wrote:maybe add an example in this thread (maybe original post) to have it for further searches. thanks.

    Done!
    0
    Thomas Thomassen — SketchUp Monkey & Coding addict
    List of my plugins and link to the CookieWare fund
    User avatar
    thomthom 
    PluginStore Author
    PluginStore Author
     

    Re: Creating attr like methods

    Postby Dan Rathbun » Thu Sep 15, 2011 6:33 pm

      Need to prepend the subject with "[Code]" so Jim's indexer will 'snag' it ...
      0
        I'm not here much anymore. But a PM will fire email notifications.
        User avatar
        Dan Rathbun 
        PluginStore Author
        PluginStore Author
         

        Re: [Code] Creating attr like methods

        Postby thomthom » Thu Sep 15, 2011 6:51 pm

        Doubledone!
        0
        Thomas Thomassen — SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund
        User avatar
        thomthom 
        PluginStore Author
        PluginStore Author
         

        SketchUcation One-Liner Adverts

        by Ad Machine » 5 minutes ago



        Ad Machine 
        Robot
         



         

        Return to Developers' Forum

        Who is online

        Users browsing this forum: allping and 11 guests

        Visit our sponsors: