librelist archives

« back to archive

green_shoes interaction with gameday_api

green_shoes interaction with gameday_api

From:
J. Kaiden
Date:
2012-04-25 @ 22:25
hello folks -

  i've been working on a baseball scorecard generator, using timothyf's
awesome `gameday_api` and (ashbb's awesome) greenShoes, and i've come
across something that's got me scratching my head...

  you'll need to install the gameday_api gem in order to test out this
snippet - https://rubygems.org/gems/gameday_api - but if it's not too much
trouble please give it a shot and let me know if you have any ideas what's
going on...

here's the snippet:

require 'gameday'
require 'team'
###require 'green_shoes'

GamedayUtil.set_fetcher('remote')
team = Team.new('bos')
p "fetching game..."
games = team.games_for_date('2012', '04', '24')
game = games[0]
gid = game.gid
p "fetching lineups..."
home = game.get_batters("home")
visitors = game.get_batters("away")

puts
home.each{|entry| p entry.batter_name}
puts
visitors.each{|entry| p entry.batter_name}

  if you run this snippet leaving the `###require 'green_shoes'` line
commented, you'll see two lists of players - one for the home team, and one
for the away team...  nifty.

  ...here's what i can't figure out - if you uncomment the line, you'll see
two lists each containing all of the players from the two original lists.
 what the heck?  i've been banging my head against the wall all night with
this one - any ideas?

  thanks -
  Shoes On...

 - j

Re: [shoes] green_shoes interaction with gameday_api

From:
Jesse Cooke
Date:
2012-04-26 @ 06:19
Wow, that's really strange. I repro'd it locally. Some strange
monkeypatching going on in the depths?

On Wed, Apr 25, 2012 at 3:25 PM, J. Kaiden <jakekaiden@gmail.com> wrote:

> hello folks -
>
>   i've been working on a baseball scorecard generator, using timothyf's
> awesome `gameday_api` and (ashbb's awesome) greenShoes, and i've come
> across something that's got me scratching my head...
>
>   you'll need to install the gameday_api gem in order to test out this
> snippet - https://rubygems.org/gems/gameday_api - but if it's not too
> much trouble please give it a shot and let me know if you have any ideas
> what's going on...
>
> here's the snippet:
>
> require 'gameday'
> require 'team'
> ###require 'green_shoes'
>
> GamedayUtil.set_fetcher('remote')
> team = Team.new('bos')
> p "fetching game..."
> games = team.games_for_date('2012', '04', '24')
> game = games[0]
> gid = game.gid
> p "fetching lineups..."
> home = game.get_batters("home")
> visitors = game.get_batters("away")
>
> puts
> home.each{|entry| p entry.batter_name}
> puts
> visitors.each{|entry| p entry.batter_name}
>
>   if you run this snippet leaving the `###require 'green_shoes'` line
> commented, you'll see two lists of players - one for the home team, and one
> for the away team...  nifty.
>
>   ...here's what i can't figure out - if you uncomment the line, you'll
> see two lists each containing all of the players from the two original
> lists.  what the heck?  i've been banging my head against the wall all
> night with this one - any ideas?
>
>   thanks -
>   Shoes On...
>
>  - j
>

Re: [shoes] green_shoes interaction with gameday_api

From:
J. Kaiden
Date:
2012-04-26 @ 10:53
hi Jesse,

  thanks for confirming - kind of strange, indeed...

  i also notice that if you just do a `p entry` at the end, instead of
`p.entry.batter_name`, the classes are represented differently - under
green they're shown html escaped, and without their attributes listed...
 hmmm....

  hope to be able to do some digging around this week - if i figure
anything out i'll certainly post back...

  thanks again,

  - j

On Thu, Apr 26, 2012 at 6:19 AM, Jesse Cooke <jesse@jc00ke.com> wrote:

> Wow, that's really strange. I repro'd it locally. Some strange
> monkeypatching going on in the depths?
>
> On Wed, Apr 25, 2012 at 3:25 PM, J. Kaiden <jakekaiden@gmail.com> wrote:
>
>> hello folks -
>>
>>   i've been working on a baseball scorecard generator, using timothyf's
>> awesome `gameday_api` and (ashbb's awesome) greenShoes, and i've come
>> across something that's got me scratching my head...
>>
>>   you'll need to install the gameday_api gem in order to test out this
>> snippet - https://rubygems.org/gems/gameday_api - but if it's not too
>> much trouble please give it a shot and let me know if you have any ideas
>> what's going on...
>>
>> here's the snippet:
>>
>> require 'gameday'
>> require 'team'
>> ###require 'green_shoes'
>>
>> GamedayUtil.set_fetcher('remote')
>> team = Team.new('bos')
>> p "fetching game..."
>> games = team.games_for_date('2012', '04', '24')
>> game = games[0]
>> gid = game.gid
>> p "fetching lineups..."
>> home = game.get_batters("home")
>> visitors = game.get_batters("away")
>>
>> puts
>> home.each{|entry| p entry.batter_name}
>> puts
>> visitors.each{|entry| p entry.batter_name}
>>
>>   if you run this snippet leaving the `###require 'green_shoes'` line
>> commented, you'll see two lists of players - one for the home team, and one
>> for the away team...  nifty.
>>
>>   ...here's what i can't figure out - if you uncomment the line, you'll
>> see two lists each containing all of the players from the two original
>> lists.  what the heck?  i've been banging my head against the wall all
>> night with this one - any ideas?
>>
>>   thanks -
>>   Shoes On...
>>
>>  - j
>>
>
>

Re: [shoes] green_shoes interaction with gameday_api

From:
ashbb
Date:
2012-04-26 @ 12:35
Hi J, Jesse and folks,

Oops. Sorry, there is a monkey patch in Green Shoes. xx-P
Look at this:
https://github.com/ashbb/green_shoes/blob/master/lib/shoes/ruby.rb#L154

So, please redefine Array#clear method like the following:

require 'gameday'
require 'team'
require 'green_shoes'

class Array
  def clear; _clear end
end

GamedayUtil.set_fetcher('remote')
team = Team.new('bos')
p "fetching game..."
games = team.games_for_date('2012', '04', '24')
game = games[0]
gid = game.gid
p "fetching lineups..."
home = game.get_batters("home")
visitors = game.get_batters("away")

puts
home.each{|entry| p entry.batter_name}
puts
visitors.each{|entry| p entry.batter_name}

ashbb

Re: [shoes] green_shoes interaction with gameday_api

From:
Peter Fitzgibbons
Date:
2012-04-26 @ 13:53
Ok, NOW you have my interest.

Why monkey Array directly instead of in-situ module extension ????
Pollution of base-ruby is a number one cause of non-interoperable libraries.

Thougths?

Peter Fitzgibbons
(847) 859-9550
Email: peter.fitzgibbons@gmail.com
IM GTalk: peter.fitzgibbons
IM AOL: peter.fitzgibbons@gmail.com


On Thu, Apr 26, 2012 at 7:35 AM, ashbb <ashbbb@gmail.com> wrote:

> Hi J, Jesse and folks,
>
> Oops. Sorry, there is a monkey patch in Green Shoes. xx-P
> Look at this:
> https://github.com/ashbb/green_shoes/blob/master/lib/shoes/ruby.rb#L154
>
> So, please redefine Array#clear method like the following:
>
> require 'gameday'
> require 'team'
> require 'green_shoes'
>
> class Array
>   def clear; _clear end
> end
>
>
> GamedayUtil.set_fetcher('remote')
> team = Team.new('bos')
> p "fetching game..."
> games = team.games_for_date('2012', '04', '24')
> game = games[0]
> gid = game.gid
> p "fetching lineups..."
> home = game.get_batters("home")
> visitors = game.get_batters("away")
>
> puts
> home.each{|entry| p entry.batter_name}
> puts
> visitors.each{|entry| p entry.batter_name}
>
> ashbb
>

Re: [shoes] green_shoes interaction with gameday_api

From:
Eric Watson
Date:
2012-04-26 @ 17:02
On Apr 26, 2012, at 8:53 AM, Peter Fitzgibbons wrote:

> Why monkey Array directly instead of in-situ module extension ????

Just to clarify, you're talking about something like the 
"SuperiorMonkeyPatch" strategy described in the article below, right?

http://subinterest.com/rubies-in-the-rough/15-learn-to-love-mix-ins

Re: [shoes] green_shoes interaction with gameday_api

From:
Peter Fitzgibbons
Date:
2012-04-26 @ 17:15
No.

BAD :
# inside my_array_patch.rb
class Array
  def clear; ... ; end
end

GOOD:
# inside awesome_array_clear.rb
module AwesomeArrayClear
  def clear; ... ; end
end
# inside "client" code that is using an array
a = []
a.extend AwesomeArrayClear
a.clear


Make sense? (Not sure if I'm being clear (pun intended))

Peter Fitzgibbons
(847) 859-9550
Email: peter.fitzgibbons@gmail.com
IM GTalk: peter.fitzgibbons
IM AOL: peter.fitzgibbons@gmail.com


On Thu, Apr 26, 2012 at 12:02 PM, Eric Watson <wasnotrice@gmail.com> wrote:

> On Apr 26, 2012, at 8:53 AM, Peter Fitzgibbons wrote:
>
> > Why monkey Array directly instead of in-situ module extension ????
>
> Just to clarify, you're talking about something like the
> "SuperiorMonkeyPatch" strategy described in the article below, right?
>
> http://subinterest.com/rubies-in-the-rough/15-learn-to-love-mix-ins
>
>
>

Re: [shoes] green_shoes interaction with gameday_api

From:
Eric Watson
Date:
2012-04-26 @ 17:33
On Apr 26, 2012, at 12:15 PM, Peter Fitzgibbons wrote:

> No.
> 
> BAD :
> # inside my_array_patch.rb
> class Array
>   def clear; ... ; end
> end
> 
> GOOD: 
> # inside awesome_array_clear.rb
> module AwesomeArrayClear
>   def clear; ... ; end
> end
> # inside "client" code that is using an array
> a = []
> a.extend AwesomeArrayClear
> a.clear
> 
> 
> Make sense? (Not sure if I'm being clear (pun intended))

It all makes sense except for the "No" part. This is exactly how the 
"SuperiorMonkeyPatch" code works in the article ;)

Apparently, it was I who was unclear. The article starts with some ways 
you might not want to approach monkeypatching, before arriving at this 
solution. Maybe that's confusing. Anyway, this is what I thought you meant
by "in-situ module extension", but I wasn't certain. I thought the article
was a nice, thorough explanation of the topic. Good reading for any 
Rubyist.

Eric

Re: [shoes] green_shoes interaction with gameday_api

From:
Date:
2012-04-26 @ 18:29
could not decode message

Re: [shoes] green_shoes interaction with gameday_api

From:
Peter Fitzgibbons
Date:
2012-04-26 @ 18:54
Don't eat cake.  Gluten.
:)

Peter Fitzgibbons
(847) 859-9550
Email: peter.fitzgibbons@gmail.com
IM GTalk: peter.fitzgibbons
IM AOL: peter.fitzgibbons@gmail.com


On Thu, Apr 26, 2012 at 1:29 PM, <deastman1@gmail.com> wrote:

> Monkey patch alert! In the real world, monkey patching is punishable by
> cake denial.
>
>
>
> -- Sent from my HP Pre3
>
> ------------------------------
> On 26 Apr 2012 18:16, Peter Fitzgibbons <peter.fitzgibbons@gmail.com>
> wrote:
>
> No.
>
> BAD :
> # inside my_array_patch.rb
> class Array
>   def clear; ... ; end
> end
>
> GOOD:
> # inside awesome_array_clear.rb
> module AwesomeArrayClear
>   def clear; ... ; end
> end
> # inside "client" code that is using an array
> a = []
> a.extend AwesomeArrayClear
> a.clear
>
>
> Make sense? (Not sure if I'm being clear (pun intended))
>
> Peter Fitzgibbons
> (847) 859-9550
> Email: peter.fitzgibbons@gmail.com
> IM GTalk: peter.fitzgibbons
> IM AOL: peter.fitzgibbons@gmail.com
>
>
> On Thu, Apr 26, 2012 at 12:02 PM, Eric Watson <wasnotrice@gmail.com>wrote:
>
>> On Apr 26, 2012, at 8:53 AM, Peter Fitzgibbons wrote:
>>
>> > Why monkey Array directly instead of in-situ module extension ????
>>
>> Just to clarify, you're talking about something like the
>> "SuperiorMonkeyPatch" strategy described in the article below, right?
>>
>> http://subinterest.com/rubies-in-the-rough/15-learn-to-love-mix-ins
>>
>>
>>
>

Re: [shoes] green_shoes interaction with gameday_api

From:
J. Kaiden
Date:
2012-04-26 @ 23:29
hey folks,

  @ashbb - thanks!!  the solution you provided works perfectly -

  i'll stay out of the monkey-patch debate ;)

  thanks to everyone for the ideas and comments - and for those of you who
could give a good god-dang about baseball, hopefully i'll have the
scorecard generator ready before too long...

  go Sox!!!
  go Shoes!!

  - j




On Thu, Apr 26, 2012 at 6:54 PM, Peter Fitzgibbons <
peter.fitzgibbons@gmail.com> wrote:

> Don't eat cake.  Gluten.
> :)
>
> Peter Fitzgibbons
> (847) 859-9550
> Email: peter.fitzgibbons@gmail.com
> IM GTalk: peter.fitzgibbons
> IM AOL: peter.fitzgibbons@gmail.com
>
>
> On Thu, Apr 26, 2012 at 1:29 PM, <deastman1@gmail.com> wrote:
>
>> Monkey patch alert! In the real world, monkey patching is punishable by
>> cake denial.
>>
>>
>>
>> -- Sent from my HP Pre3
>>
>> ------------------------------
>> On 26 Apr 2012 18:16, Peter Fitzgibbons <peter.fitzgibbons@gmail.com>
>> wrote:
>>
>> No.
>>
>> BAD :
>> # inside my_array_patch.rb
>> class Array
>>   def clear; ... ; end
>> end
>>
>> GOOD:
>> # inside awesome_array_clear.rb
>> module AwesomeArrayClear
>>   def clear; ... ; end
>> end
>> # inside "client" code that is using an array
>> a = []
>> a.extend AwesomeArrayClear
>> a.clear
>>
>>
>> Make sense? (Not sure if I'm being clear (pun intended))
>>
>> Peter Fitzgibbons
>> (847) 859-9550
>> Email: peter.fitzgibbons@gmail.com
>> IM GTalk: peter.fitzgibbons
>> IM AOL: peter.fitzgibbons@gmail.com
>>
>>
>> On Thu, Apr 26, 2012 at 12:02 PM, Eric Watson <wasnotrice@gmail.com>wrote:
>>
>>> On Apr 26, 2012, at 8:53 AM, Peter Fitzgibbons wrote:
>>>
>>> > Why monkey Array directly instead of in-situ module extension ????
>>>
>>> Just to clarify, you're talking about something like the
>>> "SuperiorMonkeyPatch" strategy described in the article below, right?
>>>
>>> http://subinterest.com/rubies-in-the-rough/15-learn-to-love-mix-ins
>>>
>>>
>>>
>>
>