Created
September 14, 2011 19:58
-
-
Save squarism/1217611 to your computer and use it in GitHub Desktop.
perl scalars vs ruby classes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I agree that Perl probably 'wins' because it just works. | |
# But consider how you'd make this work and what this means for less | |
# trivial "save typing" problems. | |
var = "1" | |
begin | |
if var > 0 | |
puts "yep" | |
end | |
rescue ArgumentError | |
puts "doesn't cast automatically" | |
end | |
if var.to_i > 0 | |
puts "Casting works. Perl has just a scalar but \ | |
Ruby has String and Fixnum classes for primatives. That's about it." | |
end | |
class String | |
def >(y) | |
if y.class == Fixnum | |
return self.to_i > y | |
end | |
#puts "meow" | |
end | |
end | |
puts "Let's try monkey patching String. Oh horror? It's a feature \ | |
that's been repeatedly lauded. See DHH's freedom patching talk." | |
if var > 0 | |
puts "yep, we can change the way > works because it's just a method." | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment