Hi! On Thu, May 22, 2014 at 7:46 PM, sergio_101 <sergio....@gmail.com> wrote:
> In many cases, an object might have a method (filter, selector, etc) > attached to it so that the object can run the correct method.. > > for instance, an object might have a filterMethod variable with a value > 'filterByArtist'.. > > in ruby, i would do something like: > > instance.send(filter_method) > > how would i do that in pharo, > Selectors (method signatures) in Pharo are represented with Symbols, not Strings. In order to send a message from a given symbol you can do: object perform: #symbol or object perform: #symbol: with: anArgument or object perform: #symbol: withArguments: anArrayOfArguments for example 2 perform: #even. 2 perform: #+ with: 3 > and is this a bad idea? > It usually depends on what you want to achieve... You can also reach the same result having two filter objects: NullFilter>>filter: aCollection ^ aCollection ByArtistFilter>>filter: aCollection ^ aCollection select: [ :each | each artist = myArtist ] And you can even think about a third solution with blocks describing the filters. Making them objects to me gives you more power. They are objects, you can manipulate them, compose them, etc. Blocks can capture variables from the scope, but they are a bit obscure (as symbols are too). > > thanks! > > > -- > ---- > peace, > sergio > photographer, journalist, visionary > #BitMessage BM-2D8VWUJSS41RFKh1ec83preVabHrnniExa > > http://www.Village-Buzz.com > http://www.ThoseOptimizeGuys.com > http://www.CodingForHire.com > http://www.coffee-black.com > http://www.painlessfrugality.com > http://www.twitter.com/sergio_101 > http://www.facebook.com/sergio101 >