Home
ruby slice_before method
Today I got a requirement to separate a array into slices when encounter several specific marks.
After search ruby api I found slice_before
method.
[1,2,3,'a',4,5,6,'a',7,8,9,'a',1,3,5].slice_before {|i| i == 'a'}.map{|n| n}
=>
[[1, 2, 3], ["a", 4, 5, 6], ["a", 7, 8, 9], ["a", 1, 3, 5]]
Pretty cool ;)
15 May 2012
Advanced capistrano usage
I was looking for a deploy lock, then found this article it introduced below usages:
- Graceful Passenger restarts
- Generating deployment stages on the fly in multi-stage environments
- Campfire notifications
- Deploy locks
- Generating servers list on the fly
(http://kpumuk.info/development/advanced-capistrano-usage/)[http://kpumuk.info/development/advanced-capistrano-usage/]
05 May 2012
How rails can use other orm's generator
I’m just suddenly curious about this, so I looked up a little about Rails source code.
I found this code is how it get the other ORM class.
Then I checked mongoid, found it has the class: Mongoid::Generators::ActiveModel
in lib/rails/mongoid_generator.rb
.
03 May 2012
what is module extend self?
Today when I reading about rails source code found
Yes, I never saw this usage before, this actually is a efficient way to change all instance methods into class methods.
Reference: (http://ozmm.org/posts/singin_singletons.html)[http://ozmm.org/posts/singin_singletons.html]
27 Apr 2012
Use rails generator to generate plugin or engine
Before I use enginx
to generate a rails engine, but after Rails 3.1 there is a new generator rails plugin new
to do the same thing now.
It will has a test/dummy
directory which used to test engine controller, model and view.
27 Apr 2012