Jason (jcreed) wrote,
Jason
jcreed

Still chugging through rails tut.
WHAT SORCERY IS THIS.
irb> User.methods.select{|x| /^find/.match x.to_s}
=> [:finder_needs_type_condition?, :find, :find_each, :find_in_batches, :find_by_sql]
irb> User.find_by_email("asdf")
  User Load (0.2ms)  SELECT "users".* FROM "users" WHERE "users"."email" = 'asdf' LIMIT 1


The surprising thing is that there is no method named "find_by_email", yet there is a method named find_by_email. There's some sort of fallback reflectiony autoload method-dispatch intervention thingy that lets you do arbitrary magic things, isn't there? Sigh.

Grumbling about that aside, I reeeally like this concrete syntax for function expressions. Holy dang.
Tags: ruby
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 14 comments