Refactor
:my
=>
'code'
Codes
Refactorings
Popular
Best
Submit
Spam
Account
Logout
Login
JavaScript doesn't seem to be activated, expect things to be ugly and sloppy!
Learn How to Create Your Own Programming Language
createyourproglang.com
Recent
Simple Particle Engine for a shooter game
Snake / Nibbles clone in C and Ncurses
Please improve
Parsing of XML data has high CPU usage
Convert simple Javascript to jQuery plugin
Active Record getting unique records
List the files in a directory without the directory name or the extension
clean the code
ohs system, recruitment software, hr software, oh&s software, human resources software, ohs software
Array parsing in a block
Popular
Parsing of XML data has high CPU usage
Please improve
Snake / Nibbles clone in C and Ncurses
List the files in a directory without the directory name or the extension
Convert simple Javascript to jQuery plugin
Simple Particle Engine for a shooter game
Active Record getting unique records
Breadth first cartesian product iterator
php refactoring
first BST
Pastable version of
Looking for comments on style and clearness
<pre class='prettyprint' language='ruby'># Ruby Quiz 2 - Scalable LCD Monitor # Gerard (smeevil) de Brieder - Govannon - 2008-06-12 class Lcd attr_accessor :line def initialize(numbers,scale) total_lines=5+((scale-1)*2) #compute the total output lines needed for scale (minimal 5) @lines=Array.new # build and reserve array spaces for the output lines total_lines.times do @lines << "" end @scale=scale numbers.scan(/./).each { |number| number_builder(get_number_sequence(number)) } end def get_number_sequence(number) #converts a given number to a sequence used by number_builder case number when "0" then @sequence="24142" when "1" then @sequence="15151" when "2" then @sequence="25232" when "3" then @sequence="25252" when "4" then @sequence="14251" when "5" then @sequence="23252" when "6" then @sequence="23242" when "7" then @sequence="25151" when "8" then @sequence="24242" when "9" then @sequence="24252" end @result='' @sequence.scan(/./).each_with_index { |seq,index| @result+=seq unless index%2==0 #add extra chars for the bigger scale lcd (@scale-1).times{ @result+=seq } end } return @result end def number_builder(sequence) #creates an lcd number from a given sequence and adds it to the lines array dashes="" spaces="" @scale.times do #define spaces and vertical dash size for scale dashes+="-" spaces+=" " end sequence.scan(/./).each_with_index do |s,i| #create the lcd number case s when "1" then @lines[i]+=" #{spaces} " when "2" then @lines[i]+=" #{dashes} " when "3" then @lines[i]+="|#{spaces} " when "4" then @lines[i]+="|#{spaces}| " when "5" then @lines[i]+=" #{spaces}| " end end end def print @lines.each { |line| puts line unless line==''} end end def check_arguments if ARGV[0]=~/^\d+$/ @scale="1" @number=ARGV[0] end if ARGV[0]=~/^-s$/ @scale=ARGV[1] @number=ARGV[2] end @scale && @number && @number=~/^\d+$/ ? true : false #are all arguments accepted ? end</pre> <pre class='prettyprint' language='ruby'>if check_arguments @lcd=Lcd.new(@number,@scale.to_i) @lcd.print else print " LCD DISPLAY =========== usage : quiz2 -s <scale> <number> example : quiz2 -s 2 12345 -s <scale> -s is optional " end</pre> <a href="http://www.refactormycode.com/codes/327-looking-for-comments-on-style-and-clearness" style="color:#fff" title="As seen on RefactorMyCode.com"><img alt="Small_logo" src="http://www.refactormycode.com/images/small_logo.gif" style="border:0" /></a>