Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4541330
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:13:08+00:00 2026-05-21T15:13:08+00:00

irb(main):001:0> t = %w{this is a test} => [this, is, a, test] irb(main):002:0> t.size

  • 0
irb(main):001:0> t = %w{this is a test}
=> ["this", "is", "a", "test"]
irb(main):002:0> t.size
=> 4
irb(main):003:0> t = %w{"this is" a test}
=> ["\"this", "is\"", "a", "test"]
irb(main):004:0> t.size
=> 4

In the end I expected t.size to be 3.

As suggested, each space has to be escaped …which turns out to be a lot of work. What other options are there? I have a list of about 30 words that I need to put in a collection because I am showing them as checkboxes using simple_form

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T15:13:09+00:00Added an answer on May 21, 2026 at 3:13 pm

    Why not just use a normal array so no one has to visually parse all the escaping to figure out what’s going on? This is pretty clear:

    t = [
        'this is',
        'a',
        'test'
    ]
    

    and the people maintaining your code won’t hate you for using %w{} when it isn’t appropriate or when they mess things up because they didn’t see your escaped whitespace.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

irb(main):001:0> require 'active_support' => true irb(main):002:0> require 'active_support/inflector/inflections' => true irb(main):003:0> ActiveSupport::Inflector.pluralize('test') => test
Consider the following: irb(main):001:0> class A irb(main):002:1> def initialize irb(main):003:2> @string = my string
I'm trying compass in irb, this is my code: C:\Documents and Settings\test>irb irb(main):001:0> require
irb(main):001:0> test = (0/1).rationalize => (0/1) irb(main):002:0> test.to_i NoMethodError: undefined method `to_i' for (0/1):Rational
C:\>irb irb(main):001:0> s = Proc.new { puts Hello } => #<Proc:0x04051780@(irb):1> irb(main):002:0> s.call Hello
In Ruby, I can define a method foo=(bar) : irb(main):001:0> def foo=(bar) irb(main):002:1> p
This works irb(main):001:0> name = Rohit Sharma => Rohit Sharma But this doesn't irb(main):001:0>
Can anyone shed some insight onto why the following happens? irb(main):001:0> r = '1'..'30'
In irb, I do this class Text include FileUtils end I get: NameError: uninitialized
I'm simply trying to get a percentage. irb(main):001:0> (25 / 50) * 100 =>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.