Skip to content

Instantly share code, notes, and snippets.

@endorama
Last active April 28, 2017 10:49
Show Gist options
  • Save endorama/68a71109f9a0f2519a64b8e21e8516e3 to your computer and use it in GitHub Desktop.
Save endorama/68a71109f9a0f2519a64b8e21e8516e3 to your computer and use it in GitHub Desktop.
Crystal lang TCS presentation
# 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}"
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
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 }
def fact(n : Int) : Int
if n == 0
return 1
end
return n * fact(n - 1)
end
puts fact 7 # => 5040
class Greeter
def initialize(name : String)
@name = name
end
def salute
puts "Hello #{@name}!"
end
end
g = new Greeter("World")
g.salute # => Hello World!
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