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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:42:04+00:00 2026-05-25T21:42:04+00:00

In the Ruby Koans , the section about_hashes.rb includes the following code and comment:

  • 0

In the Ruby Koans, the section about_hashes.rb includes the following code and comment:

def test_changing_hashes
    hash = { :one => "uno", :two => "dos" }
    hash[:one] = "eins"

    expected = { :one => "eins", :two => "dos" }
    assert_equal true, expected == hash

    # Bonus Question: Why was "expected" broken out into a variable
    # rather than used as a literal?
end

I can’t figure out the answer to the bonus question in the comment – I tried actually doing the substitution they suggest, and the result is the same. All I can figure out is that it is for readability, but I don’t see general programming advice like that called out elsewhere in this tutorial.

(I know this sounds like something that would already be answered somewhere, but I can’t dig up anything authoritative.)

  • 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-25T21:42:05+00:00Added an answer on May 25, 2026 at 9:42 pm

    It’s because you can’t use something like this:

    assert_equal { :one => "eins", :two => "dos" }, hash
    

    Ruby thinks that { ... } is a block, so it should be “broken out into a variable”, but you can always use assert_equal({ :one => "eins", :two => "dos" }, hash)

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

Sidebar

Related Questions

I am working through Ruby Koans. The test_the_shovel_operator_modifies_the_original_string Koan in about_strings.rb includes the following
I was learning ruby through ruby koans when I faced these two functions: def
In the about_symbols.rb Ruby Koan (https://github.com/edgecase/ruby_koans), I have the following code: RubyConstant = What
Ruby has two different exceptions mechanisms: Throw/Catch and Raise/Rescue. Why do we have two?
ruby-mode from svn, looks equal to 1.1 version here is emacs indentation of hash
Ruby looks a very cool language. I've started learning it for the past two
I'm trying to learn Ruby through Koans but I'm stuck on the 6th step.
I'm trying out Ruby koans and found some tests using this _n_ , never
I'm going through the ruby koans, I'm on 151 and I just hit a
I'm referring to this test in about_symbols.rb in Ruby Koans https://github.com/edgecase/ruby_koans/blob/master/src/about_symbols.rb#L26 def test_method_names_become_symbols symbols_as_strings

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.