http://www.ruby-lang.org/images/logo.gif Ruby is a DynamicallyTyped, ObjectOriented AgileLanguage, which came to popularity mainly thanks to RubyOnRails web framework. Ruby was specifically intended as an improvement over PerlLanguage, but its closest cousin is PythonLanguage. After initial rivalry, it came to be understood that Ruby and Python have complementary design goals. Ruby and Python developers are now supporting each other. '''Useful pages:''' * http://www.ruby-doc.org/ * http://www.ruby-lang.org/ * http://www.rubycentral.com/ ---- '''Hello world in Ruby:'''' print "Hello World!\n" or, using the more common Ruby idiom: puts "Hello World!" or, for CeePlusPlus fans: $stdout << "Hello World!\n"; or, for CeeLanguage fans: printf("Hello World!\n"); or, for those who like their output raw: p "Hello World!" ---- Articles: * Interviews with YukihiroMatsumoto ('Matz'), Ruby's creator: ** http://www.artima.com/intv/ruby.html ** http://www.artima.com/intv/tuesday.html ** http://www.artima.com/intv/closures.html ** http://www.artima.com/intv/craft.html * An article written by Matz: http://www.informit.com/articles/article.asp?p=18225 [1] * An introductory article by the authors of ProgrammingRuby: http://www.ddj.com/articles/2001/0101/0101b/0101b.htm [1] This article is fairly old now, and many of the complaints it has about Python no longer apply. ---- HelpMe: I need a reliable language which lives in ordinary files and has good up-to-date libraries and (most importantly) good up-to-date web frameworks. Obviously RubyLanguage is the way to go. But having used IoLanguage a lot, and also played with SmalltalkLanguage, LispLanguage and IokeLanguage, RubyLanguage just seems BORING. Can anyone help me get really excited about it please? -- JasonGrossman ''It's like with sex - language is just a tool to achieve the goal. Ruby is top-quality, but you don't want to get too excited about machine tools. Sure, Makino Seiki tool grinder is cool, but do you need it? Can it pay for itself? Do you own a workshop? Do you have a product? Customers? Ruby is comfortable, but don't believe anyone who says it is easy. Achieving full command of its power takes months for geniuses, years for us ordinary people. Unless you are solving a very difficult problem, stick with those languages you already know, or PythonLanguage, which is catching up with Ruby comfort with every new release. It is not the machine beauty, but the problem you are solving that should excite you. If it doesn't, your gut might be telling you that you are trying to do something else than you really want. Search your soul and find a more attractive goal (not necessarily in the realm of computers), and you will love the tools that help you to achieve it. BorisStitnicky'' Not sure I get the comparison with sex, but I think Boris's last three sentences are a profound observation into programming and life. -- DavidMeyer ---- '''Praise for Ruby:''' ---- For me, Ruby is the successful combination of SmallTalk's conceptual elegance, Python's ease of use and learning, and Perl's pragmatism. ---- I like it too! It has some kind of elegance, like EiffelLanguage, but it has a Perlish flavor nevertheless... I've found the developers and those on ruby-talk pretty supportive and friendly... One thing I absolutely love: Procs (i.e. code blocks)... -- DavidSdeLis (David also wants you to look at BrainLanguage, http://brain.sourceforge.net.) ---- With depth of its OO support, Ruby is close to Smalltalk. In Ruby, everything is an executable statement, and up to a small number of exceptions, these are simply method calls. For example, to declare a class with a (read-only) attribute, you could write: class Example attr :fred end The difference is, that while language syntax is not user-modifiable, methods can all be redefined by the user, including built-in classes. The 'attr' line might look like syntax, but is actually a method call to a Class object named Example (yup, Ruby has metaclasses). The user can redefine 'attr' like this: class Class def attr; puts "attr has been redefined!" end end If you want to, you could redefine #attr to trace all reads or writes to the variable, or perhaps to implement some kind of lazy persistence... Same goes for operators: 2 + 3 == 5 || 3 + 4 == 8 # result is, obviously, false is actually understood as 2.+( 3 ).==( 5 ).||( 3.+( 4 ).==( 8 ) ) where #+, #==, #|| are just method names. Add to this depth facilities such as iterators, closures, mixins, and a clean syntax, and you end up with a language that's practical for building scalable projects, but also fun to play with. ---- I played with Ruby for a short time and I like it very much. It seems to combine likeable qualities of Perl, Python, and Smalltalk (except for the use of begin/end rather than {/} to delimit block, except procs, where either do/end and {/} is allowed. The Python philosophy is a little too much "There's only one way to do it" for my taste. Ruby combines the cleanliness of Python with the flexibility and concision of Perl and the pure object-orientedness of Smalltalk. -- DanSchmidt * you can always use braces instead of keywords. --ShawnL ---- I've written scripts in Perl, Python, and Ruby. I like Ruby best by far. Now if I can get my ISP to put it up on my web site without killing me (after I pushed him for Perl and Python) ... -- RonJeffries * use Heroku (http://www.heroku.com/) ---- ---- Request for SUCCESS real file stories for ruby.... waiting for the miracle... profit... challenge... success... -- AndreySidorenko * In fact, RubyOnRails is the biggest historical success story, that put Ruby over with the audience. But otherwise, check here: http://www.ruby-lang.org/en/documentation/success-stories/ ---- One area where Ruby really shines is in creating domain specific languages. Turns out that Ruby's blocks make this easy to do. I created a Hardware Description Language/simulation environment using Ruby (RHDL) that ended up looking very much like an existing HDL (VHDL). No parser was needed - it's all pure Ruby. This would have been very difficult to do in Python since Python doesn't seem to have anything equivalent to Ruby's blocks. BTW: I was able to implement the first version of RHDL in about 300 lines of Ruby. In addition to Ruby's blocks, the fact that Ruby has continuations also helped a lot. -- PhilTomson ---- Ruby requires a lot less boilerplate than many other languages. Commands don't need to terminate with a semicolon; they simply end at endline. (Or the continue to the nextline if you implicitly state that the command's not over, using e.g. a trailing "+", or explicitly using a trailing "\".) Variable names aren't preceded with a $, method call parenthesis can be dropped... Isn't it easier to make a dumb syntactical mistake, without those restrictions? ''Sure it is, but you get used to the quirks soon enough. For more discipline, use PythonLanguage.'' ---- '''Hedging about Ruby:''' ---- Maybe I am just not willing to get too bleeding edge, but after looking at the Ruby site (URL at top of this page), I chose not to spend time learning Ruby ''at this time.'' I have been experimenting with Python, and have used it for some text manipulation projects with great success. One example is parsing an SNMP MIB and creating a header file with the corresponding MIB variables in it. That way, as Marketing changes the MIB around, I just run a script to recreate the header file. I only have to change my Cpp code if they add or remove variables. Perl seems much more widely used than Python, but Python's readability convinced me to use it. Ruby may be a better language than Python or Perl, but too few people are using it, and the documentation is still too obviously translated from Japanese for me to feel comfortable using it. -- AnonymousDonor ---- * Legacy PickAxeBook is still worth reading as a historical reference, and legacy PoignantGuideToRuby has permanent value as a work of art. Those who want to learn, should start at http://oss.org.cn/ossdocs/ruby/rug/index.html, and continue by simply reading http://ruby-doc.org/core-2.0/ class by class, starting with String class (http://ruby-doc.org/core-2.0/String.html), Array class (http://ruby-doc.org/core-2.0/Array.html), and Enumerable module (http://ruby-doc.org/core-2.0/Enumerable.html), which defines most of the iterator methods. Ruby syntax 101 can be found eg. here (http://www.tutorialspoint.com/ruby/ruby_syntax.htm) and the user will also regularly need to consult the operator precedence table, eg. http://www.techotopia.com/index.php/Ruby_Operator_Precedence. People who are serious should also get the paper book, such as "Programming Ruby 2.0" (http://pragprog.com/news/programming-ruby-2-0) ---- I'll preface this by stating that I actually love Ruby. It's a great scripting language for my needs, and I've been using it quite a bit... enough that I start running into the warty, awkward bits that plague any language. My two "favourites": * Methods don't have lexical scoping, but blocks and Procs do. This little bit of semantic incoherency has caused me a great deal of annoyance -- especially when you really need lexical behaviour, since debugging a stack full of anonymous functions isn't fun. * Here's my impression of the Ruby interpreter, ladies and gentlemen. Ahem...: $ ruby script.rb script.rb:: syntax error I swear to God, Ruby has the worst diagnostics of any program I've ever used except ed. It's like the old joke about "KenThompson's automobile"... 90% of the time, it won't say anything more useful than "syntax error", and usually it can't even give you the correct line number to start looking at. Oy gevalt! Phew, that was cathartic. ---- ''I've noticed the syntax error at end of file syndrome as well. It usually seems to mean that you started a construct but missed it's corresponding ''end''. I've been reduced to commenting out swathes of code (say, an entire class) in an attempt to track this kind of thing down. Let's say it's an area of the parser which could be improved.'' ''And while I'm on the subject, a couple of my pet peeves:'' * ''It annoys me that the parser's definition of 'obviously incomplete' doesn't include a function missing an expected block. Ruby forces you to either place a { as the last character on a line, or to use \ to indicate line continuation (like you're using the C preprocessor). Both are abhorrent. The following seems perfectly reasonable to me, but doesn't compile:'' 10.times { |i| puts i } * The reason why the above doesn't compile is that Ruby uses {/} also for Hash definition, and the above could mean the user wanting to call 10.times method without block (which is perfectly plausible, since #times is just a method, not a special keyword) and then define a Hash. To Ruby, it looks just lika a mangled hash definition. That's the price you pay for not having to type ; at the end of each line. ---- * I HaveThisPattern too, RubyLanguage looks very powerful but less usable than PythonLanguage which offers a lot of cognitive support for the programmer. I don't know if it's just my liberal arts background showing through, but code shouldn't hurt to read. -- LarryPrice ** I'm confused about the statement made here that "code shouldn't hurt to read." I've found that Ruby code is very easy on the eyes, brain, and fingers, compared to Perl or VB. That said, the sample code provided with Ruby does leave room for improvement. I think that the sample biorhythm program would hurt to read in ''any'' language, without substantial refactoring. -- DavidSaff ** I'm confused too. I've found that a good coder can write good code even in . Ruby has everything you need to write good, readable code. -- SteveMerrick ---- Speaking of refactoring - where is the RefactoringBrowser for Ruby? I've recently been getting into learning it, but I realized how spoiled I was with the EclipseIde's support for Java refactorings. -- StevenNewton ''A RefactoringBrowser for Ruby has been written: http://www.kmc.gr.jp/proj/rrb/index-en.html. It works with EmacsEditor and FreeRIDE. -- pate ---- While Ruby is nice, I can't help but think that the designer has a bit too much of the "OOP is the light and the way" philosophy in him... Ruby is not dogmatic about ObjectOrientedProgramming. Ruby is very scalable language and you can pick the appropriate style for each problem. * Check code @ MameMemo blog: http://mamememo.blogspot.com Strictly speaking, Ruby doesn't have stand-alone functions. ''As for not having stand-alone functions, try passing a block into Proc.new and the object that you get back is close enough for any use that I can think of. -- BenTilly'' ---- Oh, yeah. And = assigns, while == compares. Duh! ''One day I'd like to see a language that uses := for assignment, == for comparison, and leaves = as a syntax error.'' '''EeLanguage.''' * See AssignmentVsEqualityOperator, BondageAndDisciplineLanguage. See also: ConservationOfKeystrokes My own experience has been that rigid language doesn't prevent me from making mistakes. -- francis ''How about : for assignment and = for comparison, like the SelfLanguage? That's one character for each, and I never ever mix them up.'' How about making variables objects? ... * Deleted from here to http://bugs.ruby-lang.org/issues/8365 ---- Ruby variable symbols are preceded by 0-2 at-signs depending on their scope. Local variable is called simply last_word, instance variable @last_word, and class variable @@last_word. I don't know if Matz intended it it this way, but this makes it easier to see dependencies at a glance. * I wonder if ruby-mode in Emacs can be set up colors to distinguish single and double at-signs. (Too bad I'm not proficient in code parsing in Emacs, I'd implement it myself.) -- francis ''Have a look at http://relativity.yi.org/el/code-keywords.el. ''(BrokenLink 2005-05-01)'' It colours words like TODO and FIXME. You may be able to modify it to colour single and double at-signs.'' -- ChanningWalton ---- '''Software implemented in Ruby:''' * '''Wikis:''' ** http://www.jin.gr.jp/~nahi/RWiki/ -- Japanese-English WikiClone. Uses Ruby's RD (POD-like documentation format) as syntax. ** TiKi -- A wiki with a more conventional syntax. ** Instiki -- http://instiki.rubyforge.org/ -- A simple fast Wiki using TextileFormat or MarkDown ** An RWiki with an inline Ruby interpreter: http://www.ruby.ch/ * Metasploit -- penetration testing software. * YaST2 -- system configuration tool of openSUSE GNU/Linux 13.1 (in part auto-translated from old YaST source code). * Twitter website front end (parts of the Twitter back end are now re-implemented in the Scala language). * Google SketchUp -- the Ruby interpreter embedded in SketchUp is used for automated manipulation of 3D objects and for other extensions. ---- '''TestingFrameworks''' * MiniTest : http://www.rubyinside.com/a-minitestspec-tutorial-elegant-spec-style-testing-that-comes-with-ruby-5354.html. (now part of the Ruby standard library) * RSpec : http://net.tutsplus.com/tutorials/ruby/ruby-for-newbies-testing-with-rspec/ ---- '''User stories''' ---- As a long time Perl user, I love the power of Perl, but have been dissatisfied with the cryptic nature of Perl code. In particular, using objects in Perl is painful. I've been meaning to make the move to Python just to get better OO support, but I was finding it difficult to translate my Perl based knowledge into Python. I discovered Ruby this past summer and found it easy to make the switch from Perl to Ruby. All the power of Perl, with a clean syntax and an OO system that is very reminiscent of Smalltalk. I highly recommend looking into Ruby. -- JimWeirich ---- In a bake-off between Java, Python and Ruby for my new Web site project, we selected Ruby and I'm very happy. I love the language syntax - it is short and readable at the same time, matches my intuitive thinking mode even better than Smalltalk (I evaluate a language on that and shortnes of typing [millimemes/keystroke is the unit of measure, but it has to stay readable]. ... That having been said, I detest the @ and @@ variable names as they really clutter up the eye and make the rest of the code harder to read, and the absence of a development environment is . Programming back in the 1980s, (shudder). ... So you might take it as strong evidence of the niceness of the language that we are using it anyway. -- AlistairCockburn ''(See TheProblemWithSigils about @ and @@)'' ---- In summary, this language makes you feel loved. (In remarkable contrast to some other languages.) -- PhlIp ---- I personally like to use Ruby too but I've found some quirks that bother me slightly. A few weeks back I was deciding whether to use Python or Ruby and I read both tutorials. In the end (after a long self-debate) I chose for Ruby as it's cleaner, though it lacks the richness in libraries of Python. Recently, however, I've noticed the quirk I was mentioning: when you access an instance-variable with an attr_reader, you can modify it. (Description of user's encounter with passing by reference followed here.) Now I know that Ruby uses pass-reference-by-value (Like Java) but still, I'd expect an attr_reader to give a cloned object... Just my 2 cents -- ChristophePoucet P.S: I still use Ruby happily * Your problem is trivially solvable by meta-programming, which quickly becomes a habit in Ruby - or at least did for me. I'd do something like: class Class def attr_clone *args args.each { |arg| class_exec { define_method arg do send( arg ).clone end } } end end # Later use this newly defined cloning accessor: class Foo attr_clone :myvar end This really helps cut down on code size a lot. -- EivindEklund I have used both Ruby and Squeak (SmalltalkLanguage implementation) and I must say that while Ruby is more pragmatic, Squeak is more interesting. The whole environment understands objects, the browser is absolutely fantastic, etc. I think if there was a Squeak-like environment for Ruby, it would be great. Although Ruby is pure OO, Smalltalk is even more. I like that ifTrue:, ifFalse: and ifTrue:ifFalse: are methods of the boolean class. * Ruby's lack of a monolithic graphical IDE will be viewed by some as a feature, not a bug. ---- I don't see people complaining about ugly Perlisms in Ruby. Though I quite like Ruby, I felt since the beginning that a lot of fluff needs to be thrown out. All of those $-initial variables (especially $_, aaargh), and the statement modifiers. * try require "English" http://www.ruby-doc.org/stdlib/libdoc/English/rdoc/index.html --ShawnLandden ---- "Come to think of it, does Ruby have higher order functions?" Ruby has a convention for higher order function emulation, yes. Sadly, it's not unified with the block mechanism, which aims at partly the same solutions. BTW: Can you write anonymous "functions" like these (objects with a call method) in Ruby? (''Answer: Yes'') And less related, can an iterator (or whatever a method receiving a block is called) pass the block to a subroutine? (''Answer: Yes'') ---- '''Final remarks and references''' ---- See InspectEvalFileFormat, BlocksInRuby Bow before RubyForge. Learn to use RubyGems. Use Bundler to create your own gems. ---- '''Ruby interfaces to other programming tools''' * Call to CeePlusPlus code from Ruby using the SimplifiedWrapperAndInterfaceGenerator. ** A useful feature which helps with this is RubyCoerce. * Call inline C (RubyInlineGem) * Call from CeePlusPlus to Ruby with callbacks using RubyEmbed. * Learn to use GtkTwoGem (gem install gtk2, requires gtk libraries). ---- '''RubyGui''' There are several ways to form a Ruby GUI. Try eg. RuguiGem. ---- '''Interprocess Communication using Ruby''' * RindaGem from RubyStdLib * DistributedRuby ---- '''Logging from Ruby''' * LogForRuby ---- '''Embed Ruby in a web page''' * EeRuby (see also MongrelEeRuby, MerbAndRailsMerge) ---- '''Ruby Books''' * AgileWebDevelopmentWithRails (about RubyOnRails) * ProgrammingRuby * TheRubyWay * DesignPatternsInRuby * Large list of Ruby books: http://ruby-doc.org/bookstore ---- '''Ruby Patterns''' * DesignPatternsInRuby (book see above) * PatternsAndPractices (wiki) * PatternImplementations (on the same wiki) ---- CategoryProgrammingLanguage CategoryRuby CategoryScripting