Wednesday 3 October 2012

Rotate a Array in Rupy

 
There is solution to Rotate an array in Ruby programming language


irb(main):001:0> a = [1,2,3]
 => [1, 2, 3]
 irb(main):002:0> a.push a.shift
 => [2, 3, 1]
 irb(main):003:0>
 
 
Put these together in the Array class, and you'll be able to rotate any array easily. 


 class Array
   def rotate
     push shift
   end
 end
 

Ruby is a dynamic, reflective, general-purpose object-oriented programming language that combines syntax inspired by Perl with Smalltalk-like features. It was also influenced by Eiffel and Lisp. Ruby was first designed and developed in the mid-1990s by Yukihiro "Matz" Matsumoto in Japan. Ruby supports multiple programming paradigms, including functional, object oriented, imperative and reflective. It also has a dynamic type system and automatic memory management; it is therefore similar in varying respects to Smalltalk, Python, Perl, Lisp, Dylan, Pike, and CLU. The standard 1.8.7 implementation is written in C, as a single-pass interpreted language. The language specifications for Ruby were developed by the Open Standards Promotion Center of the Information-Technology Promotion Agency (a Japanese government agency) for submission to the Japanese Industrial Standards Committee and then to the International Organization for Standardization. It was accepted as a Japanese Industrial Standard (JIS X 3017) in 2011[8] and an international standard (ISO/IEC 30170) in 2012.[9] As of 2010, there are a number of complete or upcoming alternative implementations of Ruby, including YARV, JRuby, Rubinius, IronRuby, MacRuby (and its iOS counterpart, RubyMotion), and HotRuby. Each takes a different approach, with IronRuby, JRuby, MacRuby and Rubinius providing just-in-time compilation and MacRuby also providing ahead-of-time compilation. The official 1.9 branch uses YARV, as will 2.0 (development), and will eventually supersede the slower Ruby MRI.

No comments:

Post a Comment