Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
szabgab committed Jun 30, 2021
1 parent aee2572 commit 7fe1afe
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 2 deletions.
1 change: 1 addition & 0 deletions crystal/examples/strings/tr.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
puts "abcdeabcde".tr("ab", "xy")
1 change: 1 addition & 0 deletions crystal/examples/strings/tr.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
xycdexycde
13 changes: 13 additions & 0 deletions crystal/examples/struct/integers.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
struct Int
def prime?
(2..(self ** 0.5).to_i).each { |num|
return false if self % num == 0
}
return true
end
end

puts 23.odd?
puts 23.even?
puts 23.prime?
puts 20.prime?
5 changes: 5 additions & 0 deletions crystal/examples/time/add_timespan.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ now = Time.utc
tomorrow = now + Time::Span.new(days: 1)
puts now
puts tomorrow

puts now + 1.days
puts now + 24.hours
puts now + 1440.minutes
puts now + 86_400.seconds
8 changes: 6 additions & 2 deletions crystal/examples/time/add_timespan.out
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
2021-06-11 10:06:03 UTC
2021-06-12 10:06:03 UTC
2021-06-29 14:31:14 UTC
2021-06-30 14:31:14 UTC
2021-06-30 14:31:14 UTC
2021-06-30 14:31:14 UTC
2021-06-30 14:31:14 UTC
2021-06-30 14:31:14 UTC
6 changes: 6 additions & 0 deletions crystal/strings.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,9 @@

![](examples/strings/split_string.cr)

## String Transliteration
{id: string-transliteration}
{i: tr}

![](examples/strings/tr.cr)

5 changes: 5 additions & 0 deletions crystal/structs.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@

![](examples/struct/struct_with_initializer.cr)

## Extend other structs
{id: extend-other-structs}

![](examples/struct/integers.cr)

6 changes: 6 additions & 0 deletions crystal/time.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,16 @@

## Add timespan
{id: add-timespan}
{i: days}
{i: hours}
{i: minutes}
{i: seconds}

![](examples/time/add_timespan.cr)
![](examples/time/add_timespan.out)

* See these methods at [Int](https://crystal-lang.org/api/Int.html)

## Time Types
{id: time-types}

Expand Down

0 comments on commit 7fe1afe

Please sign in to comment.