Skip to content

Instantly share code, notes, and snippets.

@squarism
Created September 14, 2011 19:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save squarism/1217611 to your computer and use it in GitHub Desktop.
Save squarism/1217611 to your computer and use it in GitHub Desktop.
perl scalars vs ruby classes
# 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