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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:47:25+00:00 2026-05-23T14:47:25+00:00

I understand that x == y in Ruby interpreted as a.==(y) . I tried

  • 0

I understand that x == y in Ruby interpreted as a.==(y). I tried to check if I can achieve the same with custom method, foo, like this:

class Object
  def foo(n)
    self == n
  end
end

class A
  attr_accessor :x
end

a = A.new
a.x = 4

puts a.x.==(4)   # => true
puts a.x.foo(4)  # => true

puts a.x == 4    # => true
puts a.x foo 4   # => in `x': wrong number of arguments (1 for 0) (ArgumentError)

Unfortunately, this doesn’t work. What am I missing ? Is == a special method in Ruby ?

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

    No, == is not a special method in Ruby. It’s a method like any other. What you are seeing is simply a parsing issue:

    a.x foo 4
    

    is the same as

    a.x(foo(4))
    

    IOW, you are passing foo(4) as an argument to x, but x doesn’t take any arguments.

    There is, however, special operator syntax, which allows you to write

    a == b
    

    instead of

    a.== b
    

    for a limited list of operators:

    ==
    !=
    <
    >
    <=
    >=
    <=>
    ===
    &
    |
    *
    /
    +
    -
    %
    **
    >>
    <<
    !==
    =~
    !~
    

    Also, there is special syntax that allows you to write

    !a
    

    and

    ~a
    

    instead of

    a.!
    

    and

    a.~
    

    As well as

    +a
    

    and

    -a
    

    instead of

    a.+@
    

    and

    a.-@
    

    Then, there is

    a[b]
    

    and

    a[b] = c
    

    instead of

    a.[] b
    

    and

    a.[]= b, c
    

    and last but not least

    a.(b)
    

    instead of

    a.call b
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I understand that neither a abstract class nor an interface can contain a method
I know that I can write a Ruby case statement to check a match
I've been trying to understand how Ruby blocks work, and to do that I've
I understand that Microsoft uses this template when versioning their products: Major.Minor.Build.Revision. Major is
I understand that method_missing is something of a last resort when Ruby is processing
I am just starting Ruby and learning the concept of modules. I understand that
Can I do that? I'm afraid that this can be an overkill and eventually
Please understand that I'm not trying to bash RVM. I would just like to
Ruby Newbie here, I understand that everything is an object in Ruby, one thing
In Ruby 1.9 you can have Fixnum , Float , and Symbol values that

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.