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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:07:22+00:00 2026-05-31T07:07:22+00:00

Browsing the ruleby source code, I noticed that they were calling Container(:and) , which

  • 0

Browsing the ruleby source code, I noticed that they were calling Container(:and), which is something I rarely see. In fact, the only other place I’ve seen it is in the fabrication gem

A quick look showed that Container subclasses Array, and a quick hop into Pry showed that Array(:anything) #=> [:anything].

Another quick look at the ruby documentation for Array doesn’t shed much light on to this question.

What method is being called by Array(), where is it documented, how can one define a method like this, and is it considered “bad form” 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-31T07:07:23+00:00Added an answer on May 31, 2026 at 7:07 am

    For your first question, the answer is that it makes an array of its parameters.

    For your second, I have no clue, but it’s simple enough.

    For your third, here it is: In Ruby, defining a global method with the same name as the class is considered good form only when used to construct or convert from object of that type of a more fundamental type. You should not define this method unless you are creating some sort of low type. You could define this for some class like BigInt128 but you shouldn’t for ObscureOrSpecializedType678. There is also a design for these methods.

    If the data that you are passed is of the returned type, return it. If the data is of a directly related type, perform obvious conversions (Fixnum to BigInt128). If the data passed in can be converted and is somewhat related (String to Fixnum) convert it (this conversion is usually only for String). If the data can not be converted, throw an exception. You should NEVER return a “magic value”.

    The other use of this method is to create a semi-literal syntax for non-literal types. The best examples of this are Rational() and Complex(). These functions, in addition to doing conversions, allow you to create rations and complex numbers in a more natural way (Rational(1, 2) vs. Rational.new(1, 2)). If there is a certain argument list that is simpler to the literal representation of a type, you would define a Classname() method.

    For the most part, these methods are only part of the core language, and unless you are making a class like BigInt128 or FancyString or NaturalNumber, you should not define these methods.


    From what I know the defined of these are:

    • Array(*args) — Returns arguments as an array
    • Complex(real, complex) — Create a complex number with given real and complex parts
    • Float(arg) — Returns arg converted to a float (takes things like strings too)
    • Integer(arg) — Same as Float(), but converts to an integer(floats are truncated)
    • Rational(numerator, denominator=1) — Creates a Rational number with the given parts
    • String(arg) — Converts argument to string by calling to_s

    Also, some classes define [] as a class method, which is used for more complex initialization from basic data types (usual initialization only, not conversion) such as Hash[].

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

Sidebar

Related Questions

After browsing some old code, I noticed that some classes are defined in this
While browsing through the source code of the java.util.concurrency package, I noticed an idiomatic
While browsing through source code in my IDE I'll sometimes wish I could see
While browsing with Chrome, I noticed that it responds extremely fast (in comparison with
When browsing ASP.NET MVC source code in codeplex , I found it is common
While browsing some source code I came across a function like this: void someFunction(char
Browsing through the source code of Microsoft's sample StockTrader application, I found this snippet
While browsing the code of some websites I sometimes notice that some JavaScript files
Was browsing the jQuery source code when I met this line: jQuery(this)[ state ?
I am browsing the code of a large open source application and would like

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.