Midwest Dev Chat

MidwestDevChat.com

  • The newest 15 messages in the super-cool #ruby channel.

  • 08/19 21:05:18 Georgianne: I’ll show you the AST diff when I can get to a computer
  • 08/19 21:50:19 Georgianne:
    [3] pry(main)> Ripper.sexp("Integer()")
    => [:program, [[:method_add_arg, [:fcall, [:@const, "Integer", [1, 0]]], [:arg_paren, nil]]]]
    [4] pry(main)> Ripper.sexp("Integer")
    => [:program, [[:var_ref, [:@const, "Integer", [1, 0]]]]]
    [5] pry(main)> 
    
  • 08/19 21:52:41 Georgianne: here's the compiled ISEQ:
    [9] pry(main)> puts RubyVMInstructionSequence.compile("Integer()").disasm
    == disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(1,9)>==================
    0000 putself                                                          (   1)[Li]
    0001 opt_send_without_block <callinfo!mid:Integer, argc:0, FCALL|ARGS_SIMPLE>, <callcache>
    0004 leave            
    => nil
    [10] pry(main)> puts RubyVMInstructionSequence.compile("Integer").disasm
    == disasm: #<ISeq:<compiled>@<compiled>:1 (1,0)-(1,7)>==================
    0000 getinlinecache   7, <is:0>                                       (   1)[Li]
    0003 getconstant      :Integer
    0005 setinlinecache   <is:0>
    0007 leave            
    => nil
    
  • 08/19 21:53:34 Georgianne: so, you can see when the parser first interprets the text `Integer()` it sees something entirely different than when it sees `Integer`
  • 08/19 21:54:00 Georgianne: and the compiled iseq instructions are doing completely different things at the vm level
  • 08/19 21:57:30 Georgianne: This takes advantage of the fact that method lookup ends up at `Kernel` if it can't find the method in the local `binding`
  • 08/19 21:57:52 Georgianne: `Kernel` is the special object used for "global" methods
  • 08/19 21:58:10 Georgianne: so you're really just calling `Kernel.send :Integer, "100"`
  • 08/19 21:58:42 Lonnie: shocked_face_with_exploding_head
  • 08/19 23:01:43 Hyon: I prefer to ruby without knowing any of this slightly_smiling_face
  • 08/20 06:58:24 Lonnie: LOL. Yeah, I was just curious.
  • 08/20 10:21:40 Deloras: I Ruby without knowing anything…
  • 08/20 10:21:46 Deloras: It’s proof that the language is far too approachable.
  • 08/20 10:21:55 Deloras: I just type sentences until the interpreter stops complaining.
  • 08/20 15:04:10 Hyon: haha
  • *Usernames have been changed to protect the innocent.
We're currently 1197 members strong. Join us!
Request Invite

Check out all the cool channels!

Join the conversation!