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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:40:43+00:00 2026-05-22T00:40:43+00:00

the behavior I’m looking for is so I can define methods to get results

  • 0

the behavior I’m looking for is so I can define methods to get results like these:

> 2i
=> Complex(0,+2i)
> 2²
=> 4
  • 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-22T00:40:43+00:00Added an answer on May 22, 2026 at 12:40 am

    For the first one, you could add a custom instance methods to Fixnum like this:

    class Fixnum
      def i
        Complex(0, self)
      end
    end
    
    > 2.i
    # => (0+2i)
    

    And as J-_-L pointed out, you could do the same for the second one in Ruby 1.9, though your rb file will need # encoding: utf-8 at the top.

    And as DNNX pointed out, the issue of creating imaginary numbers in Ruby is already addressed by the Complex class:

    require 'complex'
    2.im 
    #=> (0+2i)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can you have smart behavior for the home key in Emacs? By smart I
Let me describe the behavior I get: Load a user from the database: this
Desired Behavior: After using the Like button on top of my fan page, I
Expected Behavior Under normal circumstances, I can issue tshark -E separator='@' under linux See
This behavior is strange because I could not get the segfault if the shared
I've seen this behavior for years. Checkboxes and radios buttons can not be covered
This is a behavior I noticed several times before and I would like to
I see some strange behavior on the maximum heap size I get on Sun's
Weird behavior when mixing loading of assemblies using Assembly.LoadFrom and Assembly.Load : I have
The behavior I propose: A user loads up my search page, www.site.com/search, types their

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.