1
2
3
4
def remove_insults(sentence)
  sentence.gsub(/#{%w( stupid moron dumbass retard ).join('|')}/i) { |insult| '*' * insult.size }
end
...

Ruby On Rubyize this : 3rd edition

by hungryblank, October 12, 2007 13:39 Star_fullStar_fullStar_fullStar_full

This solution uses a differ...

Ada486a7a6724ac155c537674f6942ae Talk
1
500.times { puts((1..16).map { rand(10) }.to_s) }

Ruby On Random number generator

by hungryblank, October 03, 2007 03:34 Star_fullStar_fullStar_fullStar_full

and in case you really want...

Ada486a7a6724ac155c537674f6942ae Talk
1
2
3
4
500.times { puts((1..16).inject('') { |a,n| a << '1234567890'[rand(10),1] }) }

# or
...

Ruby On Random number generator

by hungryblank, October 03, 2007 03:25

stressing a bit the [] meth...

Ada486a7a6724ac155c537674f6942ae Talk
1
2
3
4
# samples
# show_value_or_default(user, :phone)
# show_value_or_default(user2, :phone, "leeg")
...

Ruby On Show a default value if obj...

by hungryblank, October 03, 2007 02:50 Star_fullStar_fullStar_fullStar_full

As a first step you can avo...

Ada486a7a6724ac155c537674f6942ae Talk
1
2
3
array_of_arrays_of_hashes = array_of_hashes.map { |e| e[:callid] }.uniq.inject([]) do |grouped_array, callid|
  grouped_array << array_of_hashes.select { |h| h[:callid] == callid }
end

Ruby On Grouping an array of hashes

by hungryblank, October 01, 2007 15:40

I thought for you it was im...

Ada486a7a6724ac155c537674f6942ae Talk
1
2
3
4
class Investment < Struct.new(:start_year, :start_value, :interest_rate)

  def value_at(year)
...

Ruby On compound interest

by hungryblank, October 01, 2007 09:38 Star_fullStar_fullStar_fullStar_full

This is just an example on ...

Ada486a7a6724ac155c537674f6942ae Talk
1
2
3
4
CssObj = Struct.new(:selector, :attributes)
class CssObj
  def self.extract_file(filename)
...

Ruby On Extracting style from a CSS...

by hungryblank, September 28, 2007 04:39

I just played some mins aro...

Ada486a7a6724ac155c537674f6942ae Talk