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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:47:14+00:00 2026-06-11T15:47:14+00:00

Do operators in Ruby belong to a particular class ? As per my knowledge

  • 0

Do operators in Ruby belong to a particular class ? As per my knowledge operators are tokens which are redefined by classes according to the operation they are intended to perform. For example the Numeric class defines the + operator for numeric operations, similarly the String class defines it for string concatenation. So based on that if i try to do this:

    +.is_a ? (Numeric)

It returns false. Is my explanation to this question correct ?

Sorry for all the confusion this is the actual question from my assignment.What class does + belong to and how do you check it ?

  • 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-11T15:47:16+00:00Added an answer on June 11, 2026 at 3:47 pm

    Most of what is an operator in other programming languages, is just a method in Ruby.

    + is a method not an operator. You can get reference to it:

    1.method(:+)
    #=> #<Method: Fixnum#+>
    
    "".method(:+)
    #=> #<Method: String#+>
    

    Fixnum and String are ones of many classes that implement + method. You can define your own operator-like methods:

    class MyClass
      attr_accessor :number, :string
    
      def +(other)
        self.number += other.number
        self.string += other.string
        self
      end
    end
    

    Examples of true operators in Ruby, you can’t define your own methods with some of these ‘names’:

    • assignment operators: =
    • action AND assignment: +=, -=, *=, /=, %=, **=
    • bitwise operators: &, |, ^, ~, <<, >>
    • logical operators: and, or, &&, ||, !, not
    • ternary operator: ? :
    • range operators: .., ...
    • dot and double colon: ., ::

    There is also a special operator defined?. It actually looks like a method but it’s an operator. You can define your own defined? method, though.

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

Sidebar

Related Questions

So, I am trying to define the operators + and += for a Ruby
As C# operators e.g. +, +=, == are overridable. It lets me think they
I'm talking about operators which not return a value but modify (overwrite) the first
I am still struggling with bitwise operators using Ruby. Getting a value 11100 (28
Is there a list anywhere of all ruby operators that can be overridden? (Not
Possible Duplicate: Is there any wisdom behind “and”, “or” operators in Ruby ? What
In order to implement auto-vivification of Ruby hash, one can employ the following class
What is the difference between the && and and operators in Ruby?
Possible Duplicate: Is there any wisdom behind “and”, “or” operators in Ruby? Ruby logical
In Ruby 1.8 and earlier, Foo is a constant (a Class, a Module, or

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.