background preloader

Ruby

Facebook Twitter

Python Vs Ruby Code Examples. Moved from PythonVsRuby: (See also PythonRubyAttrComparison, PythonRubyInitializer) In RubyLanguage, every object has a method called "method_missing", which is called every time an undefined method is invoked.

Python Vs Ruby Code Examples

You can override method_missing, for super-reflective ease in creating things such as facades. Does PythonLanguage have this feature? In Python you would override the method __getattr__(self, name). From this method you can either delegate to another method or throw an exception. Class Facade(object): def __getattr__(self, what): try: return super(Facade, self). I'm writing some code in Python and I have come across a situation where, in Ruby, I would factor out a new control structure. Def upload( self, data, filename ): tmp_filename = self.temp_filename_for( filename ) attempts = self.attempts while 1: try: self.ftp.storbinary( "STOR " + tmp_filename, StringIO(data) ) return except IOError, ex: if attempts == 0: raise IOError, ex else: self.

Another approach might use currying. Python Vs Ruby. Using Ruby to Control Lego Mindstorms NXT - Tim Dysinger. Jonathan Hui. Ruby Literal Array [1, 2, 3, 4, 5] # 5 elements array [a..z, A..Z] # An array of two ranges [[1,2],[3,4]] # Nested arrays [1..2, [1,2,4], 4, "val"] # Mixed type Array[1,2,3] # [1, 2, 3] [0,1]*2 # [0, 1, 0, 1] Breaking text into a Ruby array words = %w[Break this into an array of words] # ["Break", "this", ..., "words"] letters = %w|aa b c d| # ["aa", "b", "c", "d"] letters = %W(aa b c d) # ["aa", "b", "c", "d"] Instantiate an Ruby array.

RVM: Ruby Version Manager - RVM Basics. $ rvm help # Documentation Index Wondering why you should use RVM? For a start, not only does RVM make installing multiple ruby interpreters / runtimes easy and consistent, it provides features such as gemsets that aren't typically supported out of the box on most ruby installs. RVM also lets you use different rubies in a manner that wont mess with your existing ruby install (unless you tell it to) as well as letting you run multiple different rubies in seperate terminals concurrently! Getting started First, you must ensure that you install RVM .

Post Install Configuration The rvm installation documentation instructs you to put the following line at the very end of your bash profile: [[ -s "$HOME/.rvm/scripts/rvm" ]] && . NOTE: This is for a user install. For those who are not very familiar with bash scripting, I will explain in the next few paragraphs what the line above does. [[ condition ]] evaluates the condition inside the double brackets and returns true or false. . Deploying with JRuby. About this Book 224 pages Published: Release: P1.0 (2012-07-09) ISBN: 978-1-93435-697-5 NEW: See this video on using Torquebox for high-availability deployment on the JVM.

Deploying with JRuby

JRuby deployments have fewer moving parts and consume less memory than traditional Ruby deployments, but to deploy your apps on the JVM, you need to learn some new approaches. This book introduces you to three JRuby deployment strategies that will give you the performance and scalability you need while letting you use the language you love. You’ll start by porting an existing application to JRuby, preparing the app to take advantage of the JVM platform.

With your environment in place, you’ll experiment with simple JRuby deployment with Warbler as you package your Ruby web application into a single file you can deploy to a Java application server. Deploying with JRuby is the missing link between enjoying JRuby and using it in the real world to build high-performance, scalable applications. Using the Ruby Development Tools plug-in for Eclipse. Editor's note: To learn what's new and changed in RDT since this article was written, read the developerWorks article "Easy Ruby development, the Eclipse way.

Using the Ruby Development Tools plug-in for Eclipse

" Why Ruby? Why would any self-respecting Java developer care about Ruby? Ruby is a general-purpose scripting language created 10 years ago in Japan. Contrary to popular belief, it is a pure object-oriented language. Unlike Java technology, Ruby has no scalars, so everything, including integers, are first-class objects.

Ruby is also red-hot right now. The other reason to start playing with Ruby is that all the cool kids are doing it. One of the main limiting factors to widespread development in Ruby is a good development environment (for those who don't want to learn Emacs). Back to top Setup. 東 . Blog. MacRuby & Xcode 4: Build a Self-Contained MacRuby Application - The Ranger Station. MacRuby » Home. MacRuby Intro.