Created
July 6, 2010 08:21
-
-
Save woodie/465160 to your computer and use it in GitHub Desktop.
convert list to int[]
This file contains 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
import stdlib.Array | |
import java.util.Arrays | |
class ArrayTest | |
def self.from_list | |
ints = Array.of_ints [3,6,2,9,5,7,4,8] | |
Arrays.sort(ints) | |
for i in ints | |
puts i | |
end | |
end | |
end | |
puts ArrayTest.from_list | |
# when you pass in lists of junk, bad things happen | |
# ints = Array.of_ints [3,"foo",2,9.0,"bar",7,4,8] | |
# java.lang.String cannot be cast to java.lang.Integer |
This file contains 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
# make sure this is compiled and on your $CLASSPATH | |
# http://github.com/takeru/dubious/blob/master/lib/stdlib/array.duby | |
$ duby array_test.duby | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
null |
This file contains 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment