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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:28:38+00:00 2026-06-02T17:28:38+00:00

I’m working on an exercise where I have to create a roman to arabic

  • 0

I’m working on an exercise where I have to create a roman to arabic number converter. As far as I can tell, the code below is totally kosher, but I keep getting an error when I run my tests. Ruby thinks there’s an undefined method or variable on line 37 (noted by comment below).

I’m wondering if my snytax is off or if it’s something else. Suggestions?

class ArabicNumeral

  def replace_troublesome_roman_numerals(letters)
   tough_mappings = {"CM" => "DCCCC",  "CD" => "CCCC", "XC" => "LXXXX", "XL" => "XXXX", "IX"=> "VIIII", "IV" => "IIII"}
   tough_mappings.each { |roman, arabic|   letters = letters.gsub(roman, arabic) } 
   letters
  end

  def convert_and_add(letters)
    digits = { "M" => 1000, "CM" => 900, "D" => 500, "C" => 100, "XC" => 90, "L" => 50, "XL" => 40, "X" => 10, "IX" => 9, "V" => 5, "IV" =>  4, "I" => 1}
    letters = letters.split("")
    letters.inject(0) do |sum, letter|
      arabic = digits[letter]
      sum += arabic
    end  
  end

  def self.convert(letters)
    roman_string = replace_troublesome_roman_numerals(letters)  ###LINE 37!
    arabic_number = convert_and_add(roman_string)
    arabic_number
  end
end 
  • 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-02T17:28:39+00:00Added an answer on June 2, 2026 at 5:28 pm

    The problem here is the method you are calling on line 37. replace_troublesome_roman_numerals(letters). The problem is the method self.convert(letters) is a class method. You can call it like this:

    ArabicNumeral.convert(letters)
    

    However, it contains a call to an instance variable (being that replace_troublesome_roman_numerals(letters) I mentioned earlier.

    def self.convert(letters)
        roman_string = ArabicNumeral.new.replace_troublesome_roman_numerals(letters)
        ArabicNumeral.new.convert_and_add(roman_string)
    
    end
    

    This creates an instance of ArabicNumeral and calls the method you need without saving it to a variable and taking up memory. I also removed the variable arabic_number from your method because you are calling convert_and_add(roman_string), adding it to the variable, and then returning the variable. since convert_and_add(roman_string) is the last thing handled by the method, it will return this anyway without the variable.

    If you never plan on using those methods in an instance of ArabicNumeral then I would suggest making all the methods class level or wrapping them in a Module that you would include in your projects. If you don’t plan on using them outside of the ArabicNumeral class at all, consider putting them behind a protected or private while leaving convert(letters) available.

    class ArabicNumberal
    
    def self.convert(letters)
       # Code...
    end
    
    private
    
    def self.replace_troublesome_roman_numerals(letters)
       # Code...
    end
    
    def self.convert_and_add(roman_string)
       # Code...
    end
    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,

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.