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!
More Jobs
Recent
brute-force password cracker
Highlight Selected forms, Set default vaues, Rails, JS, Lowpro
nested array to set of html anchor tags
Prime or Not
Open hours grouping
Search nested hash
Search with fulltext, ago-condition and category
Permutation of values
Drop all Indexes in SQL Server
Simple For Loop
Popular
Small Javascript Code
Simple For Loop
Drop all Indexes in SQL Server
Permutation of values
Search with fulltext, ago-condition and category
Prime or Not
nested array to set of html anchor tags
Parsing non-delimited text
Toggle "Check all / Uncheck all" with jQuery
Search nested hash
Pastable version of
Rubyize this : 6th edition
<div style="overflow:auto;border:solid 1px #ccc;background:#000;color:#F8F8F8"> <div class="section"> <pre style="float:left;margin:0 10px;border-right:0;color:#666;">1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34</pre> <pre class="sunburst"><span style="color:#E28964;">class</span> <span style="text-decoration:underline;">VotingSystem</span> <span style="color:#AEAEAE;font-style:italic;"> <span style="color:#AEAEAE;font-style:italic;">#</span>Hello, I am Rodger the old and unhappy programmer. the variable nbrOfVotes is an array of 2 dimensions. The first dimension contains the number of votes for the answer "YES, IT SUCKS"... and the other dimension contain the number of votes for the answer "NO, IT DOESN'T SUCK". In the near future there will be other possible answers... but I don't care! I retire in 2 days!</span> <span style="color:#3E87E3;"><span style="color:#3E87E3;">@@</span>nbrOfVotes</span> <span style="color:#E28964;">=</span> <span style="color:#9B859D;">Array</span>.<span style="color:#89BDFF;">new</span> <span style="color:#AEAEAE;font-style:italic;"> <span style="color:#AEAEAE;font-style:italic;">#</span>The users who sent their vote arrive in this very top secret method!! (I retire in 2 days!)</span> <span style="color:#E28964;">def</span> <span style="color:#89BDFF;">receiveAVote</span>(<span style="color:#3E87E3;">theVote</span>) <span style="color:#E28964;">if</span> theVote <span style="color:#E28964;">==</span> <span style="color:#65B042;"><span style="color:#65B042;">"</span>YES, IT SUCKS<span style="color:#65B042;">"</span></span> <span style="color:#3E87E3;"><span style="color:#3E87E3;">@@</span>nbrOfVotes</span>[<span style="color:#3387CC;">0</span>] <span style="color:#E28964;">=</span> <span style="color:#3387CC;">0</span> <span style="color:#E28964;">if</span> <span style="color:#3E87E3;"><span style="color:#3E87E3;">@@</span>nbrOfVotes</span>[<span style="color:#3387CC;">0</span>].<span style="color:#89BDFF;">nil?</span> <span style="color:#3E87E3;"><span style="color:#3E87E3;">@@</span>nbrOfVotes</span>[<span style="color:#3387CC;">0</span>] <span style="color:#E28964;">=</span> <span style="color:#3E87E3;"><span style="color:#3E87E3;">@@</span>nbrOfVotes</span>[<span style="color:#3387CC;">0</span>] <span style="color:#E28964;">+</span> <span style="color:#3387CC;">1</span> <span style="color:#E28964;">else</span> <span style="color:#E28964;">if</span> theVote <span style="color:#E28964;">==</span> <span style="color:#65B042;"><span style="color:#65B042;">"</span>NO, IT DOESN'T SUCK<span style="color:#65B042;">"</span></span> <span style="color:#3E87E3;"><span style="color:#3E87E3;">@@</span>nbrOfVotes</span>[<span style="color:#3387CC;">1</span>] <span style="color:#E28964;">=</span> <span style="color:#3387CC;">0</span> <span style="color:#E28964;">if</span> <span style="color:#3E87E3;"><span style="color:#3E87E3;">@@</span>nbrOfVotes</span>[<span style="color:#3387CC;">1</span>].<span style="color:#89BDFF;">nil?</span> <span style="color:#3E87E3;"><span style="color:#3E87E3;">@@</span>nbrOfVotes</span>[<span style="color:#3387CC;">1</span>] <span style="color:#E28964;">=</span> <span style="color:#3E87E3;"><span style="color:#3E87E3;">@@</span>nbrOfVotes</span>[<span style="color:#3387CC;">1</span>] <span style="color:#E28964;">+</span> <span style="color:#3387CC;">1</span> <span style="color:#E28964;">else</span> puts <span style="color:#65B042;"><span style="color:#65B042;">"</span>THIS IS NOT A VALID ANSWER YOU MORON... btw i retire in 2 days!<span style="color:#65B042;">"</span></span> <span style="color:#E28964;">end</span> <span style="color:#E28964;">end</span> <span style="color:#E28964;">end</span> <span style="color:#AEAEAE;font-style:italic;"> <span style="color:#AEAEAE;font-style:italic;">#</span>This is the function that compile ALL the votes... I retire in 2 days!</span> <span style="color:#E28964;">def</span> <span style="color:#89BDFF;">compileAllTheVotes</span> <span style="color:#E28964;">for</span> i <span style="color:#E28964;">in</span> (<span style="color:#3387CC;">0</span>..<span style="color:#3387CC;">1</span>) <span style="color:#E28964;">if</span> i <span style="color:#E28964;">==</span> <span style="color:#3387CC;">0</span> <span style="color:#3E87E3;"><span style="color:#3E87E3;">@@</span>nbrOfVotes</span>[<span style="color:#3387CC;">0</span>] <span style="color:#E28964;">=</span> <span style="color:#3387CC;">0</span> <span style="color:#E28964;">if</span> <span style="color:#3E87E3;"><span style="color:#3E87E3;">@@</span>nbrOfVotes</span>[<span style="color:#3387CC;">0</span>].<span style="color:#89BDFF;">nil?</span> puts <span style="color:#65B042;"><span style="color:#65B042;">"</span>HERE IS THE NUMBER OF VOTES FOR 'YES IT SUCKS' : <span style="color:#65B042;">"</span></span> <span style="color:#E28964;">+</span> <span style="color:#3E87E3;"><span style="color:#3E87E3;">@@</span>nbrOfVotes</span>[<span style="color:#3387CC;">0</span>].<span style="color:#89BDFF;">to_s</span> <span style="color:#E28964;">else</span> <span style="color:#E28964;">if</span> i <span style="color:#E28964;">==</span> <span style="color:#3387CC;">1</span> <span style="color:#3E87E3;"><span style="color:#3E87E3;">@@</span>nbrOfVotes</span>[<span style="color:#3387CC;">1</span>] <span style="color:#E28964;">=</span> <span style="color:#3387CC;">0</span> <span style="color:#E28964;">if</span> <span style="color:#3E87E3;"><span style="color:#3E87E3;">@@</span>nbrOfVotes</span>[<span style="color:#3387CC;">1</span>].<span style="color:#89BDFF;">nil?</span> puts <span style="color:#65B042;"><span style="color:#65B042;">"</span>HERE IS THE NUMBER OF VOTES FOR 'NO IT DOESN'T SUCKS' : <span style="color:#65B042;">"</span></span> <span style="color:#E28964;">+</span> <span style="color:#3E87E3;"><span style="color:#3E87E3;">@@</span>nbrOfVotes</span>[<span style="color:#3387CC;">1</span>].<span style="color:#89BDFF;">to_s</span> <span style="color:#E28964;">end</span> <span style="color:#E28964;">end</span> <span style="color:#E28964;">end</span> <span style="color:#E28964;">end</span> <span style="color:#E28964;">end</span> </pre> </div> </div> <a href="http://www.refactormycode.com/codes/283-rubyize-this-6th-edition" 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>