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 6597933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:16:24+00:00 2026-05-25T18:16:24+00:00

In the book I’m reading to learn Rails (RailsSpace) , the author creates two

  • 0

In the book I’m reading to learn Rails (RailsSpace) , the author creates two functions (below) to turn all caps city names like LOS ANGELES into Los Angeles. There’s something I don’t get about the first function, below, however.

Namely, where does “word” come from? I understand that “word” is a local/block variable that disappears after the function has been completed, but what is being passed into/assigned to “word.” IN other words, what is being split?

I would have expected there to have been some kind of argument taking an array or hash passed into this function…and then the “each” function run over that..

def capitalize_each
  space = " "
  split(space).each{ |word| word.capitalize! }.join(space)     
end   

# Capitalize each word in place.     
def capitalize_each!
  replace capitalize_each end
end
  • 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-25T18:16:24+00:00Added an answer on May 25, 2026 at 6:16 pm

    At first I thought that the method was incomplete because of the absence of self at the beginning but it seems that even without it split is being called over the string given, space would simply be a default separator. This is how the method could look with explicit self.

    class String
        def capitalize_each(separator = ' ')
            self.split(separator).each{|word| word.capitalize!}.join(separator)
        end
    end
    
    puts "LOS ANGELES".capitalize_each #=> Los Angeles
    puts "LOS_ANGELES".capitalize_each('_') #=> Los_Angeles
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The book I am reading says that SQL Server supports two kinds of character
What book would you recommend to learn test driven development? Preferrably language agnostic.
Each book can have many authors. And each author can author many books. class
If Book aggregates Chapter which in turn aggregates Page, then what should be the
Book I’ learning from claims that intArray has two dimensions. But since calling intArray.GetLength(1)
My Book model has an author attribute which today is simply a CharField. The
The book says The WPF Button class only adds two simple concepts on top
I am reading a book about Javascript and jQuery and using one of the
class Book(models.Model): name = models.CharField(max_length=127, blank=False) class Author(models.Model): name = models.CharField(max_length=127, blank=False) books =
The book I'm reading about Erlang has exercises in the back of it and

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.