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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:43:26+00:00 2026-05-27T14:43:26+00:00

Here’s the problem… I have a method that I’m calling to strip out characters

  • 0

Here’s the problem…

I have a method that I’m calling to strip out characters and convert strings to floats.

def convert_to_float(currency)
  return currency.gsub(/regex/, "").to_f
end

I have another method that is receiving string values. What I’m wanting to do is iterate those received strings through the convert_to_float method instead of applying the gsub to each line. Here is what I’ve got… is this even possible with the way I’m doing this?

def verify_amounts(total,subtotal,tax)
  arrayoftotals = [total,subtotal,tax]
  arrayoftotals.each do |convert_to_float|
  end

  ftotal = arrayoftotals[0]
  raise "ftotal must be a Float" unless ftotal.kind_of? Float
end

So far its raising the fault stating that the type is not a float which is telling me that the do each loop isn’t converting the values.

Help.

Thanks!!!

  • 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-27T14:43:27+00:00Added an answer on May 27, 2026 at 2:43 pm

    Upon closer inspection there are two things going wrong here.

    1. Your syntax to pass a method as an iterative function is wrong.

      arrayoftotals.each do |convert_to_float|
      end
      

      Works out to be an empty block where the local variable is called convert_to_float. The syntax you’re looking for is:

      arrayoftotals.each (&method (:convert_to_float)) 
      

      This passes a Proc object referring to the method convert_to_float as your block.

    2. You are not updating the values within arrayoftotals. So even if convert_to_float was being called, it wouldn’t do anything.

      Either change gsub to gsub! to destructively sanitize your strings in place, or use map! instead of each to replace each element in the array with the results of calling the function on it. map! is a better choice because it means you won’t have to adjust every other usage of convert_to_float.

    Putting it all together:

    def convert_to_float(currency)
      return currency.gsub(/regex/, "").to_f
    end
    
    def verify_amounts(total,subtotal,tax)
      arrayoftotals = [total,subtotal,tax]
      arrayoftotals.map! (&method (:convert_to_float)
    
      ftotal = arrayoftotals[0]
       raise "ftotal must be a Float" unless ftotal.kind_of? Float
    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's a problem I ran into recently. I have attributes strings of the form
Here is my problem...I have a page that loads a list of clients and
Here is the issue I am having: I have a large query that needs
Here's my scenario - I have an SSIS job that depends on another prior
Here's a coding problem for those that like this kind of thing. Let's see
Here is my problem : I have a post controller with the action create.
Here's my problem I have this javascript if (exchRate != ) { function roundthecon()
Here is my code (Say we have a single button on the page that
Here is another spoj problem that asks how to find the number of distinct
Here's what I'm trying to accomplish with this program: a recursive method that checks

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.