<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-947335392550281731</id><updated>2012-02-17T04:11:36.991+03:00</updated><category term='ruby'/><category term='ruby rails emacs ctags'/><category term='rails 3.1 migration self change'/><category term='Emacs'/><category term='RubyOnRails'/><title type='text'>Walk and ye shall reach.</title><subtitle type='html'>RubyOnRails Android Linux etc.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://itstickers.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/947335392550281731/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://itstickers.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Pavel Nikitin</name><uri>https://profiles.google.com/101475487758954655460</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-vYo-8aQhWKM/AAAAAAAAAAI/AAAAAAAAAI0/fn9KKd0ZK3s/s512-c/photo.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>5</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-947335392550281731.post-1276430624623610251</id><published>2011-07-28T21:43:00.000+03:00</published><updated>2011-07-28T21:43:02.979+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rails 3.1 migration self change'/><title type='text'>#change</title><content type='html'>&lt;p&gt;Do you now about change?&lt;/p&gt;&lt;p&gt;In Rails 3.1 ActiveRecord::Migration we can define only one method&lt;/p&gt;&lt;p&gt;change&lt;/p&gt;&lt;p/&gt;It`s 'reversible' migrations. You just implement 'up' version and Migration system generate for you methods to create revers migration.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;pre class="brush:ruby"&gt;class CreateWagons &lt; ActiveRecord::Migration&lt;br /&gt;  def change&lt;br /&gt;    create_table :wagons do |t|&lt;br /&gt;      t.integer :number&lt;br /&gt;      t.integer :mileage&lt;br /&gt;      t.datetime :build_date&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;When you run migration 'up' it create a new table, if 'down' - drop dable. But you must be careful using this magick, because some methods can`t be resolved and you get ActiveRecord::IrreversibleMigration&lt;/p&gt;&lt;p&gt;Rails known how to revert this commands:&lt;/p&gt;&lt;pre class="brush:ruby"&gt;add_column&lt;br /&gt;add_index&lt;br /&gt;add_timestamp&lt;br /&gt;create_table&lt;br /&gt;remove_timestamps&lt;br /&gt;rename_column&lt;br /&gt;rename_index&lt;br /&gt;rename_table&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;There for you can create 'change' migration. Try to run it 'up' and 'down', and if you migration raised, you just implement 'down' version.&lt;/p&gt;&lt;p&gt;I think it`s one more beautiful issues that presents to us Rails platform.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/947335392550281731-1276430624623610251?l=itstickers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://itstickers.blogspot.com/feeds/1276430624623610251/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://itstickers.blogspot.com/2011/07/change.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/947335392550281731/posts/default/1276430624623610251'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/947335392550281731/posts/default/1276430624623610251'/><link rel='alternate' type='text/html' href='http://itstickers.blogspot.com/2011/07/change.html' title='#change'/><author><name>Pavel Nikitin</name><uri>https://profiles.google.com/101475487758954655460</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-vYo-8aQhWKM/AAAAAAAAAAI/AAAAAAAAAI0/fn9KKd0ZK3s/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-947335392550281731.post-544982862507354381</id><published>2011-04-29T14:50:00.001+03:00</published><updated>2011-04-29T14:51:57.171+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby rails emacs ctags'/><title type='text'>sticker</title><content type='html'>&lt;p&gt;This sticker i must put on my display :) command to create TAGS file&lt;/p&gt;&lt;pre class="brush:bash"&gt;$ cd rails_root_path&lt;br /&gt;$ ctags -e -a --Ruby-kinds=-f -o TAGS -R .&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/947335392550281731-544982862507354381?l=itstickers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://itstickers.blogspot.com/feeds/544982862507354381/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://itstickers.blogspot.com/2011/04/sticker.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/947335392550281731/posts/default/544982862507354381'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/947335392550281731/posts/default/544982862507354381'/><link rel='alternate' type='text/html' href='http://itstickers.blogspot.com/2011/04/sticker.html' title='sticker'/><author><name>Pavel Nikitin</name><uri>https://profiles.google.com/101475487758954655460</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-vYo-8aQhWKM/AAAAAAAAAAI/AAAAAAAAAI0/fn9KKd0ZK3s/s512-c/photo.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-947335392550281731.post-4745788847719926932</id><published>2011-04-22T17:56:00.000+03:00</published><updated>2011-04-22T17:56:21.470+03:00</updated><title type='text'>Inside rails.</title><content type='html'>&lt;p&gt;You must be very careful when create "before_*" callbacks in Rails.&lt;/p&gt;&lt;p&gt;I found one interesting feature (of course it is not bug :D ) ActiveRecord raise with error RecordNotSaved if you have "before_*" callback that return "false". For example:&lt;/p&gt;&lt;pre class="brush:ruby"&gt;class User &lt; ActiveRecord::Base&lt;br /&gt;  before_save :set_short_link&lt;br /&gt;&lt;br /&gt;  private&lt;br /&gt;  def set_short_link&lt;br /&gt;    short_link = name.to_url if name.changed?&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;You can`t save instance of this class if you don`t change "name" because method "set_short_link" return false (see /activerecord/lib/active_record/base.rb, line 2568)&lt;/p&gt;&lt;p&gt;Right version will be:&lt;/p&gt;&lt;pre class="brush:ruby"&gt;class User &lt; ActiveRecord::Base&lt;br /&gt;  before_save :set_short_link&lt;br /&gt;&lt;br /&gt;  private&lt;br /&gt;  def set_short_link&lt;br /&gt;    short_link = name.to_url if name.changed?&lt;br /&gt;    true&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/947335392550281731-4745788847719926932?l=itstickers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://itstickers.blogspot.com/feeds/4745788847719926932/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://itstickers.blogspot.com/2011/04/inside-rails.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/947335392550281731/posts/default/4745788847719926932'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/947335392550281731/posts/default/4745788847719926932'/><link rel='alternate' type='text/html' href='http://itstickers.blogspot.com/2011/04/inside-rails.html' title='Inside rails.'/><author><name>Pavel Nikitin</name><uri>https://profiles.google.com/101475487758954655460</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-vYo-8aQhWKM/AAAAAAAAAAI/AAAAAAAAAI0/fn9KKd0ZK3s/s512-c/photo.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-947335392550281731.post-549748755410353385</id><published>2010-11-19T19:12:00.004+02:00</published><updated>2010-11-20T01:43:44.754+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><category scheme='http://www.blogger.com/atom/ns#' term='RubyOnRails'/><category scheme='http://www.blogger.com/atom/ns#' term='Emacs'/><title type='text'>All about ~/.emacs</title><content type='html'>&lt;p&gt;As most of the time I work with Ruby and Ruby on Rails and Emacs is my favorite text editor I would like to devote my next post to the Emacs configuration.&lt;/p&gt;&lt;p&gt;Last week I have been customizing Emacs in order to simplify my work. Therefore, i would like to share my work with you.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Theme&lt;/b&gt;&lt;/p&gt;&lt;p&gt;I started with Emacs theme customization and used color-theme plugin, which can be found on &lt;a href="http://www.nongnu.org/color-theme/"&gt;Emacs color-theme plugin homepage&lt;/a&gt; or can be taken from Debian repository in emacs-goodies-el package. After the installation you have three options:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;Use one of the build-in themes (M-x color-theme-select);&lt;/li&gt;&lt;li&gt;Create your own theme;&lt;/li&gt;&lt;li&gt;Use mine :) (&lt;a href="https://gist.github.com/664177"&gt;color theme&lt;/a&gt;)&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;For the options 2 and 3 you have to save the theme file into Emacs path directory and add the following line into your ~/.emacs file:&lt;/p&gt;&lt;pre class="brush: lisp"&gt;;; Theme&lt;br /&gt;(load-file "~/.emacs.d/color-theme-butcher.el")&lt;br /&gt;(color-theme-butcher)&lt;br /&gt;&lt;br /&gt;(set-frame-font "-misc-fixed-medium-r-normal--15-*-75-75-c-90-koi8-r")&lt;br /&gt;(tool-bar-mode)&lt;br /&gt;(menu-bar-mode)&lt;br /&gt;(scroll-bar-mode)&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;Also, as you have noticed, I set the custom font using set-frame-font (the font was chosen in xfontsel), disabled: toolbar, menubar and scrollbar.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Rinari&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Afterwards, I chose Rinari from a large list of Emacs Rails plugins. &lt;a href="http://rinari.rubyforge.org/index.html"&gt;Rinari homepage.&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Rinari installation:&lt;/p&gt;&lt;pre class="brush: bash"&gt;$ git clone git://github.com/eschulte/rinari.git&lt;br /&gt;$ cd rinari&lt;br /&gt;$ git submodule init&lt;br /&gt;$ git submodule update&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;The base Rinari directory is placed into Emacs path directory and the following code is added to ~/.emacs &lt;/p&gt;&lt;pre class="brush: lisp"&gt;;; Rinari&lt;br /&gt;(add-to-list 'load-path "~/.emacs.d/rinari/")&lt;br /&gt;(require 'rinari)&lt;br /&gt;(add-hook 'ruby-mode-hook&lt;br /&gt;          (lambda ()&lt;br /&gt;            (defadvice ruby-mode-set-encoding&lt;br /&gt;              (around ruby-mode-set-encoding-disable activate) nil)))&lt;/pre&gt;&lt;p&gt;The last hook for ruby-mode deactivates Emacs coding tags, automatically created by Emacs coding-system (that can be very uncomfortable while working with files that have Cyrillic symbols).&lt;/p&gt;&lt;p&gt;&lt;b&gt;Ruby Electric&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Unfortunately, Rinari does not include ruby-electric (helper for automatic brackets closure or any other language construction). To add ruby-electric copy ruby-electric.el to Emacs path directory and configure it into ~/.emacs&lt;/p&gt;&lt;pre class="brush: lisp"&gt;;; Ruby-electric&lt;br /&gt;(require 'ruby-electric)&lt;br /&gt;(add-hook 'ruby-mode-hook 'ruby-electric-mode)&lt;/pre&gt;&lt;p&gt;&lt;b&gt;MultiMajorModes&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Generally, Emacs uses only one major editing mode, for example, ruby-mode in *.rb files. However, if we want to edit files that contain ruby and HTML we will have to either switch the modes every time or we can install MuMaMo (MultiMajorModes). MuMaMo automatically highlights the code and switches the major modes. Most often MuMaMo is used in *.html.erb files to edit ruby and HTML. MuMaMo is based on nXhtml. You can download the latest version of nXhtml (MuMaMo included) &lt;a href="http://ourcomments.org/cgi-bin/emacsw32-dl-latest.pl"&gt;here&lt;/a&gt;.&lt;/p&gt;Unzip the archive and copy it into Emacs path directory. Add to ~/.emacs the following:&lt;/p&gt;&lt;pre class="brush: lisp"&gt;;; MuMaMo-Mode for rhtml files&lt;br /&gt;(add-to-list 'load-path "~/.emacs.d/nxhtml/util/")&lt;br /&gt;(require 'mumamo-fun)&lt;br /&gt;(setq mumamo-chunk-coloring 5)&lt;br /&gt;(add-to-list 'auto-mode-alist '("\\.rhtml\\'" . eruby-html-mumamo))&lt;br /&gt;(add-to-list 'auto-mode-alist '("\\.html\\.erb\\'" . eruby-html-mumamo))&lt;/pre&gt;&lt;p&gt;As I don`t like colored hunks, I set the variable MuMaMo-chunk-coloring being equal 5. This means that the coloring will turn on only for the fifth level, however, usually we see only three levels maximum.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Interactively Do Things&lt;/b&gt;&lt;/p&gt;&lt;p&gt;To speed up file management in you working directory you can use IDO helper (Interactively Do Things), which is a part of Rinari package. If you dislike it you can disable it any time.&lt;/p&gt;&lt;pre class="brush: lisp"&gt;;; Interactively Do Things&lt;br /&gt;(require 'ido)&lt;br /&gt;(ido-mode t)&lt;/pre&gt;&lt;p&gt;&lt;b&gt;Git in Emacs&lt;/b&gt;&lt;/p&gt;&lt;p&gt;As I use git a lot I included git-emacs (&lt;a href="https://github.com/tsgates/git-emacs"&gt;link&lt;/a&gt;) in Emacs as well:&lt;/p&gt;&lt;pre class="brush: lisp"&gt;;; git-emacs&lt;br /&gt;(add-to-list 'load-path "~/.emacs.d/git-emacs/")&lt;br /&gt;(require 'git-emacs)&lt;br /&gt;(require 'git-status)&lt;br /&gt;(setq git-state-modeline-decoration 'git-state-decoration-large-dot)&lt;br /&gt;(global-set-key (kbd "C-x M-g") 'git-status)&lt;/pre&gt;&lt;p&gt;In the last line I bound git-status function to C-x M-g combination.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Autocompletion.&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Autocomplete plugin can be downloaded &lt;a href="http://cx4a.org/software/auto-complete/"&gt;here&lt;/a&gt;. Unpack the plugin, copy to Emacs path and configure it:&lt;/p&gt;&lt;pre class="brush: lisp"&gt;;; Autocomplete&lt;br /&gt;(add-to-list 'load-path "~/.emacs.d/")&lt;br /&gt;(require 'auto-complete-config)&lt;br /&gt;(add-to-list 'ac-dictionary-directories "/home/butcher/.emacs.d//ac-dict")&lt;br /&gt;(ac-config-default)&lt;/pre&gt;&lt;p&gt;&lt;b&gt;Rsense&lt;/b&gt;&lt;/p&gt;&lt;p&gt;As autocomplete has a short completion list. I used &lt;a href="http://cx4a.org/software/rsense/"&gt;Rsense&lt;/a&gt; to extend autocomplete functionality. Further on I will tell how to install and configure Rsense in Debian (more detailed information for other OS you can find in Rsense installation guide).&lt;/p&gt;&lt;p&gt;So, having downloaded and unpacked the archive copy it into /opt directory and add local variable RSENSE_HOME that will keep the path to Rsense root directory. Afterwards, check whether bin/rsense can be executed and then create config file from Rsense configuration script.&lt;/p&gt;&lt;pre class="brush: bash"&gt;$ wget http://cx4a.org/pub/rsense/rsense-0.3.zip&lt;br /&gt;$ unzip rsence-0.3&lt;br /&gt;$ cp -av rsense-0.3 /opt&lt;/pre&gt;&lt;p&gt;What comes to the local variable RSENSE_HOME, add to ~/.bashrc the following line using your favorite editor:&lt;/p&gt;&lt;pre class="brush: bash"&gt;export RSENSE_HOME=/opt/rsense-0.3/&lt;/pre&gt;&lt;p&gt;Save the file, close the editor and open new console tab to re-read the configuration file.&lt;/p&gt;&lt;pre class="brush: bash"&gt;$ echo $RSENSE_HOME&lt;br /&gt;/opt/rsense-0.3/&lt;br /&gt;$ cd $RSENSE_HOME&lt;br /&gt;$ chmod +x bin/rsense&lt;br /&gt;$ bin/rsense version&lt;br /&gt;RSense 0.3&lt;br /&gt;$ ruby etc/config.rb &gt; ~/.rsense&lt;br /&gt;$ cat ~/.rsense&lt;br /&gt;home = /opt/rsense-0.3&lt;br /&gt;load-path = /usr/local/lib/site_ruby/1.8:/usr/local/lib/site_ruby/1.8/i486-linux:/usr/local/lib/site_ruby/1.8/i386-linux:/usr/local/lib/site_ruby:/usr/lib/ruby/vendor_ruby/1.8:/usr/lib/ruby/vendor_ruby/1.8/i486-linux:/usr/lib/ruby/vendor_ruby:/usr/lib/ruby/1.8:/usr/lib/ruby/1.8/i486-linux:/usr/lib/ruby/1.8/i386-linux:.&lt;br /&gt;gem-path = /home/butcher/.gem/ruby/1.8:/var/lib/gems/1.8&lt;/pre&gt;&lt;p&gt;That is all about Rsense installation.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Autocomplete with Rsense&lt;/b&gt;&lt;/p&gt;&lt;p&gt;To configure Emacs for Rsense and automplete + Rsense work:&lt;/p&gt;&lt;pre class="brush: lisp"&gt;;; Rsense&lt;br /&gt;(setq rsense-home "/opt/rsense-0.3")&lt;br /&gt;(add-to-list 'load-path (concat rsense-home "/etc"))&lt;br /&gt;(require 'rsense)&lt;br /&gt;&lt;br /&gt;;; Rsense + Autocomplete&lt;br /&gt;(add-hook 'ruby-mode-hook&lt;br /&gt;          (lambda ()&lt;br /&gt;            (add-to-list 'ac-sources 'ac-source-rsense-method)&lt;br /&gt;            (add-to-list 'ac-sources 'ac-source-rsense-constant)))&lt;/pre&gt;&lt;p&gt;That`s all folks! :) You can borrow my final version of ~/.emacs file &lt;a href="https://gist.github.com/664172"&gt;here&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Have a nice coding on Ruby on Rails with Emacs!&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/947335392550281731-549748755410353385?l=itstickers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://itstickers.blogspot.com/feeds/549748755410353385/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://itstickers.blogspot.com/2010/11/all-about-emacs.html#comment-form' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/947335392550281731/posts/default/549748755410353385'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/947335392550281731/posts/default/549748755410353385'/><link rel='alternate' type='text/html' href='http://itstickers.blogspot.com/2010/11/all-about-emacs.html' title='All about ~/.emacs'/><author><name>Pavel Nikitin</name><uri>https://profiles.google.com/101475487758954655460</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-vYo-8aQhWKM/AAAAAAAAAAI/AAAAAAAAAI0/fn9KKd0ZK3s/s512-c/photo.jpg'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-947335392550281731.post-2353962462173108867</id><published>2010-10-28T14:40:00.003+03:00</published><updated>2010-10-28T16:36:18.143+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>Ruby Deal-breaker</title><content type='html'>Recently I have come across a very interesting thing while working with Ruby arrays. My goal was to convert the array into a SQL query. For example, converting the array [[1,2,3],[4,5,6,],[7,8,9,]] into the string "(1,2,3),(4,5,6),(7,8,9)". If one has any basic knowledge about iterators, it won’t be a difficulty at all.&lt;br /&gt;&lt;br /&gt;Example below:&lt;br /&gt;&lt;pre class="brush: ruby"&gt;irb(main):001:0&gt; array = [[1,2,3], [4,5,6], [7,8,9]]&lt;br /&gt;=&gt; [[1, 2, 3], [4, 5, 6], [7, 8, 9]]&lt;br /&gt;irb(main):002:0&gt; sql_values = array.map{|a| "(" + a.join(", ") + ")" }.join(", ")&lt;br /&gt;=&gt; "(1, 2, 3), (4, 5, 6), (7, 8, 9)"&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;`map` returns new array which we join using "," string.&lt;br /&gt;Also, you can put the data into SQL query manually. For example, adding any random integer values to our data:&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: ruby"&gt;irb(main):003:0&gt; sql_values = array.map{|a| "(" + (a &lt;&lt; rand(100)).join(", ") + ")" }.join(", ")&lt;br /&gt;=&gt; "(1, 2, 3, 98), (4, 5, 6, 24), (7, 8, 9, 77)"&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;However, pay attention! Of course, `map` does return the new array, but you, probably, think that the `a &amp;lt;&amp;lt; rand (100)` adds the new value to the output array only. You are wrong! The thing is that when you work with `a` inside the `map` iterator, you work with the basic array, as by default, the variables are passed by link in Ruby. Therefore, when the new data is added in the existing array, you will get the following: &lt;br /&gt; &lt;br /&gt;&lt;pre class="brush: ruby"&gt;irb(main):004:0&gt; array&lt;br /&gt;=&gt; [[1, 2, 3, 98], [4, 5, 6, 24], [7, 8, 9, 77]]&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;To create a new instance you must use the operation like ‘+’&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: ruby"&gt;irb(main):005:0&gt; sql_values = array.map{|a| "(" + (a + [rand(100)]).join(", ") + ")" }.join(", ")&lt;br /&gt;=&gt; "(1, 2, 3, 98, 93), (4, 5, 6, 24, 92), (7, 8, 9, 77, 10)"&lt;br /&gt;irb(main):006:0&gt; array&lt;br /&gt;=&gt; [[1, 2, 3, 98], [4, 5, 6, 24], [7, 8, 9, 77]]&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Thus, don’t forget that variables in ruby are passed by link and when you work with ruby iterators you work with the basic data.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/947335392550281731-2353962462173108867?l=itstickers.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://itstickers.blogspot.com/feeds/2353962462173108867/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://itstickers.blogspot.com/2010/10/using-iterators-in-ruby.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/947335392550281731/posts/default/2353962462173108867'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/947335392550281731/posts/default/2353962462173108867'/><link rel='alternate' type='text/html' href='http://itstickers.blogspot.com/2010/10/using-iterators-in-ruby.html' title='Ruby Deal-breaker'/><author><name>Pavel Nikitin</name><uri>https://profiles.google.com/101475487758954655460</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh5.googleusercontent.com/-vYo-8aQhWKM/AAAAAAAAAAI/AAAAAAAAAI0/fn9KKd0ZK3s/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry></feed>
