Short answer For an integer range : Enumerable#sum returns (range.max-range.min+1)*(range.max+range.min)/2 Enumerable#inject(:+) iterates over every element. Theory The sum of integers between 1 and n is called a triangular number, and is equal to n*(n+1)/2. The sum of integers between n and m is the triangular number of m minus the triangular number of n-1, which is equal to m*(m+1)/2-n*(n-1)/2,
I have a string which looks like a hash: "{ :key_a => { :key_1a => 'value_1a', :key_2a => 'value_2a' }, :key_b => { :key_1b => 'value_1b' } }" How do I get a Hash out of it? like: { :key_a => { :key_1a => 'value_1a', :key_2a => 'value_2a' }, :key_b => { :key_1b => 'value_1b' } } The string can have any depth of nesting. It has all the properties how a valid Hash is typed in Ruby.
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く