Created
February 10, 2017 04:00
-
-
Save marzzz21/514061a91e8a461c8a416d717c079607 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2.3.0 :001 > class SummaryRow | |
2.3.0 :002?> attr_accessor :user_id, :name | |
2.3.0 :003?> def +(row) | |
2.3.0 :004?> newRow = SummaryRow.new | |
2.3.0 :005?> newRow.user_id = @user_id | |
2.3.0 :006?> newRow.name = @name | |
2.3.0 :007?> return newRow | |
2.3.0 :008?> end | |
2.3.0 :009?> end | |
=> :+ | |
2.3.0 :010 > summary1 = SummaryRow.new | |
=> #<SummaryRow:0x00000001b90068> | |
2.3.0 :011 > summary1.user_id = 1; summary1.name = 'first' | |
=> "first" | |
2.3.0 :012 > puts summary1.inspect | |
#<SummaryRow:0x00000001b90068 @user_id=1, @name="first"> | |
=> nil | |
2.3.0 :013 > summary2 = SummaryRow.new | |
=> #<SummaryRow:0x00000001c4e9a0> | |
2.3.0 :014 > summary3 = SummaryRow.new | |
=> #<SummaryRow:0x00000001c97a88> | |
2.3.0 :015 > summary2.user_id = 2; summary1.name = 'second' | |
=> "second" | |
2.3.0 :016 > summary3.user_id = 3; summary3.name = 'third' | |
=> "third" | |
2.3.0 :017 > summary2.user_id = 2; summary2.name = 'second' | |
=> "second" | |
2.3.0 :018 > summary1.user_id = 1; summary1.name = 'first' | |
=> "first" | |
2.3.0 :019 > rows = [ summary1, summary2, summary3 ] | |
=> [#<SummaryRow:0x00000001b90068 @user_id=1, @name="first">, #<SummaryRow:0x00000001c4e9a0 @user_id=2, @name="second">, #<SummaryRow:0x00000001c97a88 @user_id=3, @name="third">] | |
2.3.0 :020 > rows2 = Array.new | |
=> [] | |
2.3.0 :021 > rows2 << rows.inject(:+) | |
=> [#<SummaryRow:0x00000001c24290 @user_id=1, @name="first">] | |
2.3.0 :022 > puts rows2 | |
#<SummaryRow:0x00000001c24290> | |
=> nil | |
2.3.0 :023 > | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment