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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:58:09+00:00 2026-06-02T19:58:09+00:00

I would like to chain my own methods in Ruby. Instead of writing ruby

  • 0

I would like to chain my own methods in Ruby. Instead of writing ruby methods and using them like this:

def percentage_to_i(percentage)
  percentage.chomp('%')
  percentage.to_i
end

percentage = "75%"
percentage_to_i(percentage)
=> 75

I would like to use it like this:

percentage = "75%"
percentage.percentage_to_i
=> 75

How can I achieve this?

  • 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-02T19:58:12+00:00Added an answer on June 2, 2026 at 7:58 pm

    You have to add the method to the String class:

    class String
      def percentage_to_i
        self.chomp('%')
        self.to_i
      end
    end
    

    With this you can get your desired output:

    percentage = "75%"
    percentage.percentage_to_i # => 75
    

    It’s kind of useless, because to_i does it for you already:

    percentage = "75%"
    percentage.to_i # => 75
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing this application which is a flashcard app, I would like to create
I would like to connect to a clustered Oracle database described by this TNS:
I would like to know what guys are using to make diagram of your
I have a decorator chain that looks like this when initially created: IType calculator
I have some classes that i'd like chain methods of to provide a fluent
I have this function. $('.anythingSlider').delegate('img','click', function(){ $('#largeImage').attr('src',$(this).attr('data-image')); }); I would like to have the
I have a Markov chain that I would like to represent graphically in javascript.
I'm trying to do the following method chain: $(somehtml).insertAfter(#someelement).fadeIn('slow'); What I would like to
I have a set of collaborating objects and I would like to keep this
Would like to be able to set colors of headings and such, different font

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.