Skip to content

Instantly share code, notes, and snippets.

@hamakn
Last active August 29, 2015 14:16
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 hamakn/79d62853541404cc0d94 to your computer and use it in GitHub Desktop.
Save hamakn/79d62853541404cc0d94 to your computer and use it in GitHub Desktop.
array << hoge || default
require "pp"
require "ripper"
pp Ripper.sexp("arr << nil || 1")
# =>
# [:program,
# [[:binary,
# [:binary,
# [:vcall, [:@ident, "arr", [1, 0]]],
# :<<,
# [:var_ref, [:@kw, "nil", [1, 7]]]],
# :"||",
# [:@int, "1", [1, 14]]]]]
pp Ripper.sexp("arr.<< nil || 1")
# =>
# [:program,
# [[:command_call,
# [:vcall, [:@ident, "arr", [1, 0]]],
# :".",
# [:@op, "<<", [1, 4]],
# [:args_add_block,
# [[:binary,
# [:var_ref, [:@kw, "nil", [1, 7]]],
# :"||",
# [:@int, "1", [1, 14]]]],
# false]]]]
pp Ripper.sexp("arr.push nil || 1")
# =>
# [:program,
# [[:command_call,
# [:vcall, [:@ident, "arr", [1, 0]]],
# :".",
# [:@ident, "push", [1, 4]],
# [:args_add_block,
# [[:binary,
# [:var_ref, [:@kw, "nil", [1, 9]]],
# :"||",
# [:@int, "1", [1, 16]]]],
# false]]]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment