User:AJFarmar: Difference between revisions

From Rosetta Code
Content added Content deleted
No edit summary
No edit summary
Line 11: Line 11:
==Ruby==
==Ruby==
===Recent code:===
===Recent code:===
I made a little method that allowed me to replace <lang ruby>"String".split</lang>
I made a little method that allowed me to replace <code ruby>"String".split(" ")[index]</code> with <code ruby>"String".word index</code>.
I know that this is relatively simple, but I still found it kinda neat.

<lang ruby>
class String

def word(index)
return self.split(" ")[index] if index.class != Range
return self.split(" ")[index].join(" ")
end

end
</lang>

Revision as of 18:29, 19 July 2014

My Favorite Languages
Language Proficiency
Ruby Very Active
Java Very Active
Python Active
JavaScript Active
UNIX Shell Rusty

AJFarmar

Anton J. Farmar, Computing student.

Ruby

Recent code:

I made a little method that allowed me to replace "String".split(" ")[index] with "String".word index. I know that this is relatively simple, but I still found it kinda neat.

<lang ruby> class String

def word(index)
 return self.split(" ")[index] if index.class != Range
 return self.split(" ")[index].join(" ")
end

end </lang>