Last active
April 28, 2017 10:49
-
-
Save endorama/68a71109f9a0f2519a64b8e21e8516e3 to your computer and use it in GitHub Desktop.
Crystal lang TCS presentation
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
# Demo of command line arguments | |
# ARGV[0]: First command line argument | |
# (not the executable name) | |
# ARGV is an array of strings | |
puts "Number of command line arguments: #{ARGV.size}" | |
ARGV.each_with_index {|arg, i| puts "Argument #{i}: #{arg}"} | |
# The executable name is available as PROGRAM_NAME | |
puts "Executable name: #{PROGRAM_NAME}" |
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
def sa(name : String) : Int32 | |
3 | |
end | |
def foo(x, y : Int32 = 1, z : Int64 = 2) | |
x + y + z | |
end | |
def foo(x : T) | |
end | |
foo(3) # x = 3, T = Int32 |
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
strs = {"peach", "apple", "pear", "plum"} | |
puts strs.index("pear") | |
puts strs.includes?("grape") | |
puts strs.any? { |v| v.starts_with? "p" } | |
puts strs.all? { |v| v.starts_with? "p" } | |
puts strs.select { |v| v.includes? "e" } | |
puts strs.map { |v| v.upcase } |
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
def fact(n : Int) : Int | |
if n == 0 | |
return 1 | |
end | |
return n * fact(n - 1) | |
end | |
puts fact 7 # => 5040 |
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
class Greeter | |
def initialize(name : String) | |
@name = name | |
end | |
def salute | |
puts "Hello #{@name}!" | |
end | |
end | |
g = new Greeter("World") | |
g.salute # => Hello World! |
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
puts Time.parse("2012-11-01 22:08:12", "%F %T") | |
puts Time.parse("Fri Oct 31 23:00:24 2014", "%c") | |
puts Time.parse("20150624", "%Y%m%d") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment