Closed bitgangsta closed 11 years ago
Right now, we've avoided all monkey-patching in PM, and I'd like to keep it that way for compatibility with other gems. I think there's already a to_image
method on String in some other gems.
Instead, this could be pretty simple:
def image_for(name)
name.is_a?(UIImage) ? name : UIImage.imageNamed(name)
end
This unfortunately doesn't allow other types, though.
How about this:
class Imagify
def initialize(name)
return name if name.kind_of? UIImage
# possibly handle other cases...
UIImage.imageNamed(name)
end
end
This would allow for more confident programming throughout the gem as all those checks for image/string can be replaced with Imagify.new(string)
or Imagify.new(image)
, and we always get what we expect.
Sugarcube includes this functionality - https://github.com/rubymotion/sugarcube/blob/master/lib/sugarcube-uikit/nsstring.rb#L3-L8
I agree with @jamonholmgren that we should be patching the base classes as little as possible, especially when there are other gems you can use in tandem with ProMotion that supply the requested functionality.
I agree with @bitgangsta that what we're doing is kinda yuk, though.
We pass image options around a bunch, and as nice as this is, it's a but nasty to constantly check and see if we have a String or UIImage.
I suggest we add a small function to the
String
class calledto_image
. And then create a helper function like:And a helper function such as:
Then we can wrap any image arguments with calls to the helper function. This also lets us accept other types (besides strings) in the future, as long as they respond to
to_image
. Sounds pretty flexible to me... what do you guys think?