Tatsuhiro Ujihisa
Tatsuhiro Ujihisa


Play with local vars

I'll demonstrate, or more precisely, play with Ruby local variables, including a discussion about the following common pitfall:

eval 'a = 1'
eval 'p a' #=> NameError!

Ruby has multiple different types of variables: global vars, instance vars, class vars, constants, local vars, and pseudo vars such as self. Identifiers without sigils such as @ are considered either local vars, methods, method arguments, block parameters, pseudo variables, or other reserved words. Particularly important aspect I believe is that Ruby intentionally tries to make local vars and methods indistinguishable for human. This talk focuses only on local vars among other variables or methods.

  • Keywords: parse.y, binding, yarv iseq, continuation, flip-flop operator, regular expression, and gdb
  • Things not likely covered by this talk: TracePoint, Vim, Refinements, DSLs, and third-party libraries.