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
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
Learning JS
Type Safety
Euler Problem 2 solution
Popular
Parsing of XML data has high CPU usage
List the files in a directory without the directory name or the extension
Convert simple Javascript to jQuery plugin
Active Record getting unique records
Breadth first cartesian product iterator
php refactoring
first BST
Learning JS
Too many if statements
clean the code
Pastable version of
Rubyize this : 4th edition
<pre class='prettyprint' language='ruby'>class Bug attr_accessor :type attr_accessor :name attr_accessor :iq attr_accessor :annoyance_factor def initialize(name,type,iq,annoyance_factor) if !type @type="spider" else @type=type end if !name @name="unnamed" else @name=name end if !iq @iq = 8 else @iq = iq end if !annoyance_factor @annoyance_factor = 4 else @annoyance_factor = annoyance_factor end end end def keep_butterflies(bugs) butterflies = Array.new bugs.each do |bug| if bug.type == "butterfly" butterflies.push(bug) end end return butterflies end #create some bugs! bugs = Array.new bugs.push(Bug.new("ron","spider","4","2")) bugs.push(Bug.new("don","spider","2","3")) bugs.push(Bug.new("jake","ant","9","4")) bugs.push(Bug.new("chris","ladybug","2","4")) bugs.push(Bug.new("fred","cockchaffer","0","5")) bugs.push(Bug.new("greg","butterfly","2","0")) bugs.push(Bug.new("jason","butterfly","0","2")) butterflies=keep_butterflies(bugs) butterflies.each do |butterfly| puts "I am a butterfly and my name is #{butterfly.name}. I have an IQ of #{butterfly.iq} and an annoyance factor of #{butterfly.annoyance_factor}" end</pre> <a href="http://www.refactormycode.com/codes/99-rubyize-this-4th-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>