SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Evangelist
    Join Date
    Jun 2004
    Location
    California
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What are those %{} things in ruby?

    Hi,

    In my quest to learn Ruby a few months ago I never did learn what the code that looks like this is:
    %w{bla bla2 bla3}

    What are those? What letters are available for after the %? What do they do?

    Thank you,
    Mitch

  2. #2
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's a Perl-style quick array. That's the way I think of them at least, there's probably a more accurate description.
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  3. #3
    SitePoint Evangelist
    Join Date
    Jun 2004
    Location
    California
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by samsm
    It's a Perl-style quick array. That's the way I think of them at least, there's probably a more accurate description.
    Do you know of a place where I can read more about them?

  4. #4
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by xmitchx
    Do you know of a place where I can read more about them?
    I'm not sure there's that much to know.
    http://phrogz.net/ProgrammingRuby/in...rraysandhashes

    hello_i_am_a_new_array = %w{space separated stuff in here}
    %w{space separated stuff in here}.any_array_method_here
    %w{space separated stuff in here}.include?('separated') => true
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  5. #5
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Location
    Norway
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's just a simple shortcut. Example:
    Code:
    $ irb
    irb(main):001:0> %w{one two three four}
    => ["one", "two", "three", "four"]
    irb(main):002:0>
    It builds an array of strings.

  6. #6
    SitePoint Guru silver trophy Luke Redpath's Avatar
    Join Date
    Mar 2003
    Location
    London
    Posts
    794
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is also %r for regexps.

  7. #7
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is general quoting syntax. qQwrx are valid specifiers.

    http://phrogz.net/ProgrammingRuby/la...delimitedinput

  8. #8
    SitePoint Evangelist
    Join Date
    Jun 2004
    Location
    California
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by stereofrog
    This is general quoting syntax. qQwrx are valid specifiers.

    http://phrogz.net/ProgrammingRuby/la...delimitedinput
    Got it! Great page, thanks a lot.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •