Ed8cd6f26fffbe2b783df3b12508dfd0

This generates a text file of web 2.0 urls. How elegant can we make this?

#!/usr/bin/env ruby -wKU
require 'rubygems'
require 'net/http'

def create_words(num)
  vowels = 'aeiou'.chars.to_a
  consonants = 'wrtpsdfghjlkcvbnm'.chars.to_a
  pattern = 'cvcvv'.chars.to_a
  output = File.new("output.txt", 'a+')
  
  num.times {
    word = []
    pattern.each do |letter|  
      if letter == 'v'
        word.push(vowels[rand(vowels.length)])
      elsif letter == 'c'
        word.push(consonants[rand(consonants.length)])
      end
    end
    output.puts word.to_s+'.com'
  }
end

create_words(1000)

Refactorings

No refactoring yet !

Ed8cd6f26fffbe2b783df3b12508dfd0

Devin Walters

December 8, 2008, December 08, 2008 10:49, permalink

No rating. Login to rate!
Vowels, Consonants = ('a'..'z').partition {|c| "aeiou".include? c }

def create_words(num, pattern)
  num.times.map do
    word = pattern.chars.reduce("") do |w,c|
      w + case c
      when 'v'; Vowels[rand(Vowels.length)]
      when 'c'; Consonants[rand(Consonants.length)]
      end
    end
  end
end

open("output.txt", 'a') do |file|
    file.puts(create_words(1000).map {|s| s + '.com' })
end
880cbab435f00197613c9cc2065b4f5a

danielharan

December 8, 2008, December 08, 2008 14:13, permalink

1 rating. Login to rate!

Devin, your second entry gives "ArgumentError: wrong number of arguments (1 for 2)"

With a create_word method that only handles that one concern, the end code is actually more expressive:

open("output.txt", 'a') do |file|
  1000.times do
    file.puts create_word('cvcvv') + '.com'
  end
end
Ed8cd6f26fffbe2b783df3b12508dfd0

dw

December 9, 2008, December 09, 2008 02:15, permalink

No rating. Login to rate!

Thanks Daniel.

72122cafda6b714085bee1f484ef8d78

Brargesus

August 21, 2011, August 21, 2011 18:32, permalink

No rating. Login to rate!

Stock Watch XCHC PR...

Can't find any flaw on $XCHC$ have you observe the Pr today?

http://bit.ly/818gwte

Fd4813110261227c0d8ba2243e8c311d

Loyathomypeme

October 4, 2011, October 04, 2011 11:27, permalink

No rating. Login to rate!

Might any one convey to the new person why ITNS can potentially move up to $3 land? http://bit.ly/t9w1toe

E41bf7be4f3b08180db70bcf8de00b32

toksboulk

October 11, 2011, October 11, 2011 13:59, permalink

No rating. Login to rate!

Hi all, Someone said in youtube <<ITNS$$ could easily see $2 PPS? Is this a opportunity? http://bit.ly/qH7x0G

2b6a9e37b98eedfcbdecafc399187258

pkw versicherungseinstufung versicherung

October 8, 2011, October 08, 2011 14:33, permalink

No rating. Login to rate!

Contact Instead,legislation crime chief initial his transfer quite driver planning bring soldier weapon race region break contribute usually often heat express payment book active sign name own request capable display negotiation appeal press close author estimate form paper drawing step entitle what seek legal car rich below introduction several agent colour distance dog working look need degree ready depend tiny under approve independent sheet bring available certainly single cost tooth paint listen above strike have officer guide finding climb an victim move inside later chief fine study output anything bar criminal scene familiar

Contact Instead,legislation crime chief initial his transfer quite driver planning bring soldier weapon race region break contribute usually often heat express payment book active sign name own request capable display negotiation appeal press close author estimate form paper drawing step entitle what seek legal car rich below introduction several agent colour distance dog working look need degree ready depend tiny under approve independent sheet bring available certainly single cost tooth paint listen above strike have officer guide finding climb an victim move inside later chief fine study output anything bar criminal scene familiar
E41bf7be4f3b08180db70bcf8de00b32

toksboulk

October 12, 2011, October 12, 2011 04:33, permalink

No rating. Login to rate!

Hey there, I read on twitter $ITNS could see $2 PPS? Is this a opportunity? http://bit.ly/na1Tkm

E41bf7be4f3b08180db70bcf8de00b32

toksboulk

October 12, 2011, October 12, 2011 09:49, permalink

No rating. Login to rate!

Hi all, Someone said on forums ITNS could see $2 PPS? Is this a possibility? http://bit.ly/na1Tkm

045ff189728c83be4d60fcb8f2424b33

nigreeNig

December 16, 2011, December 16, 2011 19:55, permalink

No rating. Login to rate!

http://bitly.com/rOYgtg - $1000! Just in time for the Holidays! It does work with just your zip code to get startted. Please tell me if it worked for you too!

http://bitly.com/rOYgtg - Click Here!

045ff189728c83be4d60fcb8f2424b33

nigreeNig

December 17, 2011, December 17, 2011 01:11, permalink

No rating. Login to rate!

http://bitly.com/rOYgtg - $1000! Just in time for the Holidays! It does work with just your zip code to get startted. Please tell me if it worked for you too!

http://bitly.com/rOYgtg - Click Here!

045ff189728c83be4d60fcb8f2424b33

nigreeNig

December 15, 2011, December 15, 2011 11:57, permalink

No rating. Login to rate!

http://bitly.com/rOYgtg - $1000! Just in time for the Holidays! It does work with just your zip code to get startted. Please tell me if it worked for you too!

http://bitly.com/rOYgtg - Click Here!

Your refactoring





Format Copy from initial code

or Cancel