mirror of
https://github.com/tiennm99/serena.git
synced 2026-10-14 04:16:34 +00:00
Add Crystal language support
This commit is contained in:
1 parent
cd1ce8dc60
commit
d8bf1365c3
10 files changed
+344
-2
No files matched your search
@@ -0,0 +1,8 @@
|
||||
name: test_repo
|
||||
version: 0.1.0
|
||||
|
||||
targets:
|
||||
test_repo:
|
||||
main: src/main.cr
|
||||
|
||||
crystal: ">= 1.0.0"
|
||||
@@ -0,0 +1,43 @@
|
||||
require "./utils"
|
||||
|
||||
class Calculator
|
||||
def add(a : Int32, b : Int32) : Int32
|
||||
a + b
|
||||
end
|
||||
|
||||
def multiply(a : Int32, b : Int32) : Int32
|
||||
a * b
|
||||
end
|
||||
end
|
||||
|
||||
struct User
|
||||
getter name : String
|
||||
getter age : Int32
|
||||
|
||||
def initialize(@name : String, @age : Int32)
|
||||
end
|
||||
|
||||
def greet : String
|
||||
"Hello, my name is #{name} and I am #{age} years old."
|
||||
end
|
||||
|
||||
def adult? : Bool
|
||||
age >= 18
|
||||
end
|
||||
end
|
||||
|
||||
module Status
|
||||
Active = 0
|
||||
Inactive = 1
|
||||
Pending = 2
|
||||
end
|
||||
|
||||
calculator = Calculator.new
|
||||
result = calculator.add(5, 3)
|
||||
puts "Result: #{result}"
|
||||
|
||||
user = User.new("Alice", 30)
|
||||
puts user.greet
|
||||
|
||||
area = Utils.calculate_area(5.0)
|
||||
puts "Circle area: #{area}"
|
||||
@@ -0,0 +1,9 @@
|
||||
module Utils
|
||||
def self.format_date(time : Time) : String
|
||||
time.to_s("%Y-%m-%d")
|
||||
end
|
||||
|
||||
def self.calculate_area(radius : Float64) : Float64
|
||||
Math::PI * radius * radius
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user