Skip to content

Instantly share code, notes, and snippets.

View asterite's full-sized avatar

Ary Borenszweig asterite

  • NoRedInk
  • Buenos Aires, Argentina
View GitHub Profile
module Moo
# Moo expects `foo` to return an Int32
abstract def foo : Int32
# `bar` adds 1 to it
def bar : Int32
foo + 1
end
# And maybe it provides other methods...
class LinkedList(T)
include Enumerable
class Node(T)
property :next
property :data
def initialize(@data : T, @next = nil)
end
end
class HtmlBuilder
def initialize
@str = StringBuilder.new
end
def build
self.yield
@str.to_s
end
class Object
def self.size
base = Pointer(self).null
(base + 1).address - base.address
end
end
struct Foo
def initialize(@x, @y, @z)
end
class Foo
property x
property y
property z
property w
def initialize
end
def dup
type = :info
time = Time.now
2_000_000.times do
msg = case type
when :success then 'alert-success'
when :error then 'alert-danger'
when :warn then 'alert-warning'
when :info then 'alert-info'
end
@asterite
asterite / initialize_overload.cr
Created May 15, 2014 19:19
initialize overload
class Foo
def initialize(x : Number)
puts "#{x} is a number!"
end
def initialize(x : String)
puts "#{x} is a string!"
end
end
; ModuleID = 'foo.ll'
target triple = "x86_64-apple-darwin12.5.0"
%String = type { i32, i32, i8 }
%"{Int32, Int32, Int32}" = type { i32, i32, i32 }
@symbol_table = global [0 x %String*] zeroinitializer
; Function Attrs: nounwind readnone
define i32 @__crystal_main(i32 %argc, i8** nocapture %argv) #0 {
def self.read_keypress
case C.getchar
when 'a'
:left
when 's'
:down
when 'd'
:right
when 'w'
:up
class StopIteration < Exception
def initialize
super("StopIteration")
end
end
module Iterator(T)
include Enumerable(T)
def map(&func : T -> U)