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

  • Home
  • SEARCH
  • 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 9183425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:47:57+00:00 2026-06-17T18:47:57+00:00

I just started with Ruby recently and I’m hoping there is a shorthand for

  • 0

I just started with Ruby recently and I’m hoping there is a shorthand for using a bound method as a proc I’m missing. I’m trying to do this essentially

SYMBOLS = {"I" => 1, "V" => 5, "X" => 10, ... }

roman = "zXXIV".upcase.chars.collect { |c| SYMBOLS[c] }
=> [nil, 10, 10, 1, 5]

I feel like there should be an easy way in ruby to just use SYMBOLS[] as a bound method, so just

roman = str.upcase.chars.collect &:SYMBOLS[]

Solution Ruby 1.9.3

roman = SYMBOLS.values_at(*str.upcase.chars)

  • 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-17T18:47:59+00:00Added an answer on June 17, 2026 at 6:47 pm
    SYMBOLS.values_at(str.upcase.chars.to_a)
    

    Regarding using SYMBOLS[], you’d still need to pass the character to the method.

    You can get the method via SYMBOLS.method(:[]), e.g.,

    > p = SYMBOLS.method(:[])
    > p.call("X")
    => 10
    

    I’m not convinced it’s the most readable in this case–for me, calling map and passing in SYMBOLS[], while concise and functional, delays understanding what’s happening longer than I prefer.

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

Sidebar

Related Questions

I have programmed in Python for a while, and just recently started using Ruby
I've just recently started learning/using Ruby at work. I've got a super-simple test script
I just recently started this ruby on rails tutorial to kick off my new
I've just started learning ruby, so this question is simple. I created @subject in
I've just started using Ruby on Rails and so far it's working nicely. I'm
I just started reading Michael Hartl's Ruby on Rails 3 Tutorial. He recommends using
Ive recently started using Ruby on Rails for a project of mine and have
Hi i just started learning ruby and i'm trying to loop through an array
I just started learning some ruby, and I want to do something like this:
I have just started coding with rails. I am using: Rails 3.2.8 ruby 1.9.3p194

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.