Skip to content

Instantly share code, notes, and snippets.

11:21 -!- Jeaiti [i=4210fd22@gateway/web/ajax/mibbit.com/x-6485f9eb1fff1160] has joined #rubyonrails
11:21 < Jeaiti> is this a ruby on rails chanel?
module ActionController
module Benchmarking
module ClassMethods
private
def perform_action_with_benchmark
logger.info("I am a carrot.")
end
end
end
end
config.load_paths += Dir["#{RAILS_ROOT}/vendor/gems/**"].map do |dir|
File.directory?(lib = "#{dir}/lib") ? lib : dir
end
"Back in the days of assembly language programming, the distance between what you intended as a programmer and how the computer forced you to express that intention was enormous. Every few lines you needed a little story to help you understand what the next few instructions really meant.
As programming languages progressed, moving the expression closer to what it really meant, the habit of commenting every few lines relaxed ...
... Someone asked me 'What percentage of your methods have comments?' I answered 'between 0 and 1 percent'..."
-- Kent Beck, Smalltalk Best Practice Patterns
+----------------------+-------+-------+---------+---------+-----+-------+
| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |
+----------------------+-------+-------+---------+---------+-----+-------+
| Libraries | 4412 | 3493 | 40 | 509 | 12 | 4 |
| Models | 11866 | 9114 | 404 | 1273 | 3 | 5 |
| Unit tests | 6049 | 4888 | 185 | 604 | 3 | 6 |
| Helpers | 6764 | 5796 | 0 | 736 | 0 | 5 |
| Controllers | 6299 | 5354 | 126 | 622 | 4 | 6 |
| Functional tests | 5885 | 4935 | 76 | 639 | 8 | 5 |
| Integration tests | 46 | 33 | 4 | 5 | 1 | 4 |
%w{ asian american european african australian }.each do |p|
map.with_options :controller => :people, :people => p do |person|
person.send(p.pluralize) p.pluralize, :action => :index, :conditions => {:method => :get}
person.send(p) p, :action => :show, :conditions => {:method => :get}
... etc
end
end
rb(main):008:0> a = 0
=> 0
irb(main):009:0> b = 1
=> 1
irb(main):010:0> Benchmark.bm {|x| x.report { 100000.times { a.zero? } } }
user system total real
0.030000 0.000000 0.030000 ( 0.020547)
=> true
irb(main):011:0> Benchmark.bm {|x| x.report { 100000.times { b.zero? } } }
user system total real
config.load_paths += Dir["#{RAILS_ROOT}/vendor/gems/**"].map do |dir|
File.directory?(lib = "#{dir}/lib") ? lib : dir
end
irb(main):001:0> class Foo
irb(main):002:1> def self.bar; p 'class'; end
irb(main):003:1> end
=> nil
irb(main):008:0> module Foo
irb(main):009:1> def self.bar; p 'module'; end
irb(main):010:1> end
TypeError: Foo is not a module
Rails
=============D
Merb
===================D