Q: how to start a module name with a lower case character?

Discussion in 'Ruby' started by Mark Watson, Jun 25, 2007.

  1. Mark  Watson

    Mark Watson Guest

    I am trying to write Ruby classes to model RDF, RDFS, and Owl, much
    like SWCLOS does for Common Lisp:

    module Rdfs
    ....
    end

    x = Rdfs::Class.new(Rdfs::Label => "label_1")

    It would be nice to have a hack that would allow module names to start
    with a lower case letter. Any ideas?

    It would also be good to be able to alias "::" to ":" so that I could
    use a syntax like:

    rdfs:Label

    Any ideas and references to things to read, no matter how hack-like,
    will be appreciated.
    Mark Watson, Jun 25, 2007
    #1
    1. Advertising

  2. On 25.06.2007 16:53, Mark Watson wrote:
    > I am trying to write Ruby classes to model RDF, RDFS, and Owl, much
    > like SWCLOS does for Common Lisp:
    >
    > module Rdfs
    > ...
    > end
    >
    > x = Rdfs::Class.new(Rdfs::Label => "label_1")
    >
    > It would be nice to have a hack that would allow module names to start
    > with a lower case letter. Any ideas?


    You can't because module names must be constants and constants have to
    start with an uppercase letter.

    > It would also be good to be able to alias "::" to ":" so that I could
    > use a syntax like:
    >
    > rdfs:Label


    Hm, no idea whether there is a way although Ruby seems to accept the syntax:

    $ ruby -ce 'rdfs:Label'
    Syntax OK

    Kind regards

    robert
    Robert Klemme, Jun 25, 2007
    #2
    1. Advertising

  3. Mark  Watson

    Phrogz Guest

    Robert Klemme wrote:
    > On 25.06.2007 16:53, Mark Watson wrote:

    [snip]
    > > It would also be good to be able to alias "::" to ":" so that I could
    > > use a syntax like:
    > >
    > > rdfs:Label

    >
    > Hm, no idea whether there is a way although Ruby seems to accept the syntax:
    >
    > $ ruby -ce 'rdfs:Label'
    > Syntax OK


    FWIW, this is because Ruby interprets that as a method call with a
    symbol argument, i.e. rdfs( :Label )

    irb(main):002:0> rdfs:Label
    NoMethodError: undefined method `rdfs' for main:Object
    from (irb):2
    irb(main):003:0> def rdfs( *args ) p args end
    => nil
    irb(main):004:0> rdfs:Label
    [:Label]

    So, with predefined or dynamic prefixes, you could use that syntax as
    a method that returns a specially-namespaced constant.
    Phrogz, Jun 25, 2007
    #3
  4. On 6/25/07, Robert Klemme <> wrote:

    > Hm, no idea whether there is a way although Ruby seems to accept the syntax:
    >
    > $ ruby -ce 'rdfs:Label'
    > Syntax OK


    Incase it wasn't clear what was going on in Logan's post, the reason
    why that syntax is okay is because it's interpreted as rdfs:)Label)
    Gregory Brown, Jun 25, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    4
    Views:
    700
    J├╝rgen Exner
    Dec 7, 2004
  2. Mark
    Replies:
    3
    Views:
    565
  3. Janice

    lower case to upper case

    Janice, Dec 10, 2004, in forum: C Programming
    Replies:
    17
    Views:
    1,160
    Richard Bos
    Dec 14, 2004
  4. Replies:
    3
    Views:
    487
    James Kanze
    Nov 18, 2007
  5. penny
    Replies:
    28
    Views:
    2,353
    Charlton Wilbur
    Mar 10, 2008
Loading...

Share This Page