to_f) / length
end
def variance
m = mean
Exception
66 | Chapter 2: ActiveSupport and RailTies
sum {|x| (x-m)**2} / length
end
def standard_deviation
variance ** 0.5
end
end
"%.2f" % [1,2,3,4,5].standard_deviation # => "1.41"
Exception core_ext/exception.rb
Four methods are added to Exception for more intuitive stack traces:
??? clean_message runs the exception message through Pathname.clean_within, which
cleans any pathnames contained within the message (removes extra slashes and
resolves . and .. paths).
??? clean_backtrace runs the entire backtrace through Exception::TraceSubstitutions and
Pathname.clean_within, to clean the pathnames. TraceSubstitutions is used by Action-
View??™s templates to hide certain unsightly parts of the backtrace when template compilation
fails.
??? application_backtrace returns the set of frames belonging to the Rails application,
excluding those that are part of the Rails framework.
??? framework_backtrace returns the set of frames that are part of the Rails framework.
Together with application_backtrace, this is used on the default Rails rescue pages in
the development environment.
File core_ext/file.rb
File.atomic_write atomically writes to a file; it creates a temporary file, yields it to a block
for writing, and then renames it to the destination. The advantage over a standard write is
that the destination file does not exist in a half-written state at any point.
Pages:
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110