Skip to content

Instantly share code, notes, and snippets.

@benlovell
Created January 10, 2013 13:54
Show Gist options
  • Save benlovell/4502179 to your computer and use it in GitHub Desktop.
Save benlovell/4502179 to your computer and use it in GitHub Desktop.
With and without ampersands.
[1,2,3,4,5].inject(0, &:+)
============= :__script__ ==============
Arguments: 0 required, 0 post, 0 total
Arity: 0
Locals: 0
Stack size: 5
Lines to IP: 1: 0..29
0000: meta_push_1
0001: meta_push_2
0002: push_int 3
0004: push_int 4
0006: push_int 5
0008: make_array 5
0010: meta_push_0
0011: push_literal :+
0013: dup_top
0014: is_nil
0015: goto_if_true 24
0017: push_cpath_top
0018: find_const 1
0020: swap_stack
0021: send_stack :__from_block__, 1
0024: send_stack_with_block :inject, 1
0027: pop
0028: push_true
0029: ret
----------------------------------------
[1,2,3,4,5].inject(0, :+)
============= :__script__ ==============
Arguments: 0 required, 0 post, 0 total
Arity: 0
Locals: 0
Stack size: 5
Lines to IP: 1: 0..18
0000: meta_push_1
0001: meta_push_2
0002: push_int 3
0004: push_int 4
0006: push_int 5
0008: make_array 5
0010: meta_push_0
0011: push_literal :+
0013: send_stack :inject, 2
0016: pop
0017: push_true
0018: ret
----------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment