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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:09:02+00:00 2026-05-29T17:09:02+00:00

I’m going through Michael Hartl’s Ruby on Rails 3.2 Tutorial and I’m confused about

  • 0

I’m going through Michael Hartl’s Ruby on Rails 3.2 Tutorial and I’m confused about why the title helper found in Section 4.1.1 doesn’t fail.

He talks about needing a title helper in the event that you leave out this bit of code from the view:

<% provide(:title, 'Home') %>

But in the application layout file there is this line:

<title><%= full_title(yield(:title)) %></title>

Doesn’t that pass a nil value to the full_title helper since the provide isn’t setting a value to the :title symbol?

Later in the chapter he has an example that is typed into the rails console which is the same as the full_title function:

def string_message(string)
  if string.empty?
  "It's an empty string!"
else
   "The string is nonempty."
 end
end

This confused me further.

At the console, if I type:

  • string_message("") then I get "It's an empty string!"
  • string_message("something") then I get "The string is nonempty."
  • string_message(nil) then I get NoMethodError: undefined method 'empty?' for nil:NilClass
  • string_message(test) then I get ArgumentError: wrong number of arguments (0 for 2..3)
  • string_message(:test) then I get "The string is nonempty."

So passing an undefined symbol does not result in a nil value? But it’s also non-empty? Why isn’t :title treated as non-empty? If someone could set me clear this up for me that would be great.

  • 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-29T17:09:04+00:00Added an answer on May 29, 2026 at 5:09 pm

    While your argument is “string”, don’t get hung up on the idea that this has to be a string. Someone could pass any argument to the function, and whether it will have problems in your function or not really only depends on whether that object responds to the “empty?” message.

    When you call

    string_message("")
    

    the call to

    "".empty?
    

    evaluates to true.

    When you pass a nil object, nil doesn’t support the empty? message, so it throws an error

    When you throw an arbitrary symbol

    string_message(:pigs_on_the_wing)
    

    you are sending the empty message to :pigs_on_the_wing, which is a symbol. Symbol defines the “empty?” message as returning true only when the body of the symbol is “”.

    For example, in irb:

    :"".empty?                # true
    :pigs_on_the_wing.empty?  #false
    

    You can always go straight to the source:

    http://www.ruby-doc.org/core-1.9.3/Symbol.html#method-i-empty-3F

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am trying to loop through a bunch of documents I have to put
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.