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

The Archive Base Latest Questions

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

What does @ stand for in the following Ruby code: module TestRocket extend Module.new

  • 0

What does @ stand for in the following Ruby code:

module TestRocket
  extend Module.new { attr_accessor :out }

  def _test(a, b); send((call rescue()) ? a : b); end

  def +@; _show _test :_pass, :_fail end
  def -@; _show _test :_fail, :_pass end
  def ~@; _show _pend;               end
  def !@; _show _desc;               end

  def _show(r); (TestRocket.out || $>) << r; r end
  def _pass; "     OK\n"; end
  def _fail; "   FAIL @ #{source_location * ':'}\n"; end
  def _pend; "PENDING '#{call}' @ #{source_location * ':'}\n"; end
  def _desc; "   FIRE '#{call}'!\n"; end
end

Proc.send :include, TestRocket

Then this is used as:

+-> { Die.new(2) }
--> { raise }
+-> { 2 + 2 == 4 }

How does @ turn into ‘->’ in the function name?

  • 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-26T06:29:27+00:00Added an answer on May 26, 2026 at 6:29 am

    The method names for the four unary operators +, -, ~, and ! are +@, -@, ~@, and !@. So the funny looking method definitions:

    def +@; _show _test :_pass, :_fail end
    def -@; _show _test :_fail, :_pass end
    def ~@; _show _pend;               end
    def !@; _show _desc;               end
    

    just define overloads for those four unary operators. Then TestRocket is patched into the Proc class using Proc.send :include, TestRocket.

    This:

    -> { Die.new(2) }
    

    is simply a lambda definition and another way of writing lambda { Die.new(2) }. Then, with TestRocket patched into Proc we can say this:

    +-> { Die.new(2) }
    # + lambda { Die.new(2) }
    

    and it will run this method:

    def +@; _show _test :_pass, :_fail end
    

    as an instance method on that lambda.

    Looks like a bit of an abuse of the unary operator overloading to “invent” something that looks like new -->, ~->, … operators.

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

Sidebar

Related Questions

Let's say I declare this: int [a][b][c]; Does a stand for the level/page, b
When we're talking about matrices or a matrix, what does unary minus stand for
How does one convert a stand-alone .tlb file created in a pre-2009 version of
What does ! mean in pseudo-code? I know ! stands for factorial but I
Possible Duplicate: What does a colon following a C++ constructor name do? I am
i have the following situation, i have a Reporting layer(stand alone) in asp.net application(NOT
Can somebody explain the following code please? #if 1 // loop type #define FOR_IS_FASTER
in ruby, :: namespaces the module and class. But I often see :: at
I've made a program for my OOP class that does the following: Defines a
What does the following problem in NetBeans 6.1 IDE stands for while working in

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.