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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:53:24+00:00 2026-06-03T17:53:24+00:00

def [](index) case index when 0, -2: @x when 1, -1: @y when :x,

  • 0
def [](index)
  case index
  when 0, -2: @x
  when 1, -1: @y
  when :x, "x": @x
  when :y, "y": @y
  else nil
  end
end

array.rb:3: syntax error, unexpected ':', expecting keyword_then or ',' or ';' or '\n'
  when 0, -2: @x
             ^
array.rb:5: syntax error, unexpected ':', expecting keyword_end
  when :x, "x": @x
               ^
array.rb:6: syntax error, unexpected ':', expecting keyword_end
  when :y, "y": @y
               ^
array.rb:8: warning: else without rescue is useless
array.rb:9: syntax error, unexpected keyword_end, expecting $end

I am writing this as is from the book, The Ruby Programming Language.

My ruby version is ruby 1.9.3p0

Has anyone seen this before?

  • 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-06-03T17:53:32+00:00Added an answer on June 3, 2026 at 5:53 pm

    I suggest you use the regular case..when..then form

    def [](index)   
      case index   
        when 0, -2 then @x   
        when 1, -1 then @y   
        when :x, "x" then @x   
        when :y, "y" then @y   
      end 
    end 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

class MyTestController < ApplicationController def index render_text hello world end end This is what
asdf = [[1,2,3],[11,22,33,44,55,66],[51]] def recursive(params, index) if (index==params.size) puts DONE end currentParam = params[index]
I have the following index action: class ExpensesController < ApplicationController def index() @expenses =
I have a view in a Django 1.4 project: def index(request): print reverse('menus_index') latest_menu_list
I am working with the following piece; def index @user = User.find(params[:id]) rescue flash[:notice]
I have this simple code in my user_controller.rb file #listing all users def index
i have this class PagesController < ApplicationController def index @textos = Texto.all @texto_historia =
I have a simple controller called list_controller with an index that basically does def
i despair in case of an array. I put some data into an array,
I am testing this controller: class SessionsController < ApplicationController def new end def create

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.