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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:41:24+00:00 2026-05-29T19:41:24+00:00

This is an example code from a book. I assume it’s for Ruby 1.8.

  • 0

This is an example code from a book. I assume it’s for Ruby 1.8.

    birthyear = 1986
    generation = case birthyear
        when 1946...1963: "Baby boomer"
        when 1964...1976: "Generation X"
        when 1977...2012: "new generation"
        else nil
    end

    puts generation

I ran it on Ruby 1.9, and got this error message:

    Untitled 2.rb:12: syntax error, unexpected ':', expecting keyword_then or ',' or ';' or '\n'
    when 1946...1963: "Baby boomer"
                     ^
Untitled 2.rb:13: syntax error, unexpected keyword_when, expecting $end
    when 1964...1976: "Generation X"

How should I change this?

  • 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-29T19:41:27+00:00Added an answer on May 29, 2026 at 7:41 pm

    There was a change in the syntax between 1.8.x and 1.9.x where the : is now no longer allowed:

     birthyear = 1986
     generation = case birthyear
       when 1946...1963
         "Baby boomer"
       when 1964...1976
         "Generation X"
       when 1977...2012
         "new generation"
       else
         nil
       end
    
     puts generation
    

    Technically : has been replaced by then but that’s an optional keyword if you use a newline. It’s a bit of a hassle to go and track down cases where you’ve used the old syntax, so hopefully searching for case is close enough.

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

Sidebar

Related Questions

This example is taken from the Linux System Programming book, page 88. Code: http://pastebin.com/mEfmHbPP
I was looking at example code from the O'Reilly book on Ruby on Rails
This is an example code from the prototype site. var url = '/proxy?url=' +
With regards this example from Code Complete: Comparison Compare(int value1, int value2) { if
I copied this code from an example . I've read it 100 times. Array.prototype.map
I was programming the example code from Frank Luna's book Introduction to 3D Game
I'm learning Python from a book, and I came across this example: M =
this is basic example I got for a GUI from a book called Java
I try to run a example code from a book and it gives errors
I copy this code from a book. In every comment I put a number

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.