6

How do you find information (via Google, preferably) about the usage of operators in code? In this case, I want to find the meaning of this code in Ruby.

x = [1,2,3]
x.send :[]=,0,2
x[0] + x.[](1) + x.send(:[],2)

I want you to teach me how to fish -- do not tell me what the operators do. When I go to Google and try to search for the notation, I get examples or tutorials that don't cover the particular usage.

https://stackoverflow.com/questions/1165786/how-to-search-for-punctuation-that-gets-ignored-by-google says that Google dismisses such notation; the way that I'm looking for an "answer" is to ask for at least one successful walkthrough from someone that can take the above code and say "Here is how I find out what the operators do".

Example of my unsuccessful searches.

  • I search for Ruby :[]= and add/remove terms like notation, operator, colon, bracket, square brackets, and can't find usage of these operators in this way.

  • I search for ruby . notation, add/remove terms like period, dot, parenthesis, etc.

  • I search for cheat sheets. Find the cheat sheet to Ruby on Rails default directory structure, regex expressions, etc., but still not what I'm looking for.

Community
  • 1
  • 1
Danny
  • 3,670
  • 12
  • 36
  • 45
  • 2
    Have you tried the `ri` command-line utility? – Ray Toal Jul 29 '12 at 22:32
  • 1
    http://symbolhound.com/?q=%5B%5D%3D and http://ruby-doc.org/core-1.9.3/Object.html#method-i-send – mu is too short Jul 29 '12 at 22:37
  • x is an Array and 'send' (which is somewhat searchable) is used to call a method on an object. So, you can head to ruby-doc.org and check Array's list of methods for []=. If that fails you can check the Array's ancestors for it. – Pete Schlette Jul 29 '12 at 23:48
  • @RayToal, what software are you assuming I've installed for me to use a command-line utility? I'd love to install it. – Danny Jul 30 '12 at 22:28
  • @muistooshort: thanks, I really like what symbolhound is trying to do and I hope our fellow engineers start explaining answers such that definitions follow. – Danny Jul 30 '12 at 22:29
  • 1
    A ruby installation normally comes with irb, ri, rdoc, and testrb. If you installed "just ruby" on your own, or are using a stripped down installation from others, you might not have it. But it should be there. In fact [this StackOverflow question](http://stackoverflow.com/questions/2941005/how-to-remove-installed-ri-and-rdoc) actually asks how ri and rdoc can be _removed_! :) – Ray Toal Jul 30 '12 at 22:48

1 Answers1

2

It's so hard not to tell you (I will if you ask).

Get a Ruby book. Try the Pickaxe, it has an entire section on Ruby operators, metaprograming, language reference, etc.

Linuxios
  • 34,849
  • 13
  • 91
  • 116
  • Roger; get The Pickaxe book (http://pragprog.com/book/ruby/programming-ruby), look up the section on Ruby operators, metaprogramming, and language references, and I will find it all. Thanks! – Danny Jul 30 '12 at 09:09
  • 1
    @Danny: Sure. It's a really great book. I call it the Ruby bible. – Linuxios Jul 30 '12 at 13:26