ruby-mpd icon indicating copy to clipboard operation
ruby-mpd copied to clipboard

Instantiate a playlist by name

Open Phrogz opened this issue 10 years ago • 0 comments

My UI uses the name of a playlist as the unique identifier. When I want to fetch a playlist with this name I must currently use one of the following:

playlist = @mpd.playlists.find{ |pl| pl.name==playlistname }
playlist = MPD::Playlist.new( @mpd, playlist:playlistname )

Using find feels gross because it instantiates all the playlists (maybe a great many) when I only need one. Using new feels gross because if I mistakenly ask for a playlist that does not exist it will be created.

I'd prefer to be able to do something like:

playlist = @mpd.playlist( playlistname )

Does that seem reasonable?

Phrogz avatar Jan 08 '16 19:01 Phrogz