Last active
August 29, 2015 14:05
-
-
Save baroquebobcat/dc27b72e3387a4a60470 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package cool.extensions | |
extension StringExt[String] | |
def toInt | |
Integer.parseInt(self) | |
end | |
end | |
# or, less overloaded w/ generics | |
extension StringExt of String | |
def toInt | |
Integer.parseInt(self) | |
end | |
end | |
# or flip it around | |
extend String with StringExt | |
def toInt | |
Integer.parseInt(self) | |
end | |
end | |
# - should it be self, or should we have a different id for the | |
# extended target? | |
# | |
# - if we have an implicit target, should fields be referred to with @ syntax? |
This file contains hidden or 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
package awesome | |
use_extension cool.extensions.StringExt | |
puts "123".toInt + 5 |
This file contains hidden or 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
package awesome | |
extensions(cool.extensions.StringExt) | |
puts "123".toInt + 5 |
This file contains hidden or 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
package awesome | |
import extension cool.extensions.StringExt | |
puts "123".toInt + 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment