From d8fce670a29229ca707b36c2f0cc40ee8f699b5f Mon Sep 17 00:00:00 2001 From: Gabor Szabo Date: Tue, 29 Jun 2021 15:55:46 +0300 Subject: [PATCH] format crystal files --- crystal/examples/add_numbers.cr | 8 +- crystal/examples/arrays/array.cr | 13 +- crystal/examples/arrays/array_iterate.cr | 6 +- crystal/examples/arrays/array_push.cr | 4 +- crystal/examples/arrays/count_digits.cr | 8 +- crystal/examples/arrays/elements.cr | 1 - crystal/examples/arrays/empty_array.cr | 14 +- crystal/examples/arrays/filter.cr | 8 +- crystal/examples/arrays/map.cr | 5 +- crystal/examples/assign_to_variable.cr | 1 - crystal/examples/backtick.cr | 6 +- crystal/examples/capture.cr | 6 +- crystal/examples/capture2.cr | 5 +- crystal/examples/case.cr | 23 +- crystal/examples/case_when_on_type.cr | 1 - crystal/examples/catch_exception.cr | 21 +- crystal/examples/check_slides.cr | 198 +++++++++--------- crystal/examples/classes/attribute_person.cr | 6 +- crystal/examples/classes/class_and_json.cr | 17 +- .../classes/class_with_declared_getter.cr | 12 +- .../class_with_declared_getter_default.cr | 12 +- .../classes/class_with_default_property.cr | 14 +- .../examples/classes/class_with_getters.cr | 21 +- .../examples/classes/class_with_property.cr | 14 +- .../examples/classes/class_with_setters.cr | 31 ++- crystal/examples/classes/compare_objects.cr | 10 +- crystal/examples/classes/person.cr | 9 +- crystal/examples/classes/person_class.cr | 12 +- .../singleton_using_class_properties.cr | 11 +- ...on_using_class_properties_with_defaults.cr | 7 +- crystal/examples/classes/use_person.cr | 11 +- crystal/examples/cli/argv.cr | 4 +- crystal/examples/cli/cli_parser.cr | 2 +- crystal/examples/cli/parse_options.cr | 1 - crystal/examples/cli/parsing_order.cr | 1 - crystal/examples/cli/some_program.cr | 4 +- crystal/examples/default.cr | 1 - crystal/examples/divide_by_zero.cr | 5 +- crystal/examples/docspec/src/app.cr | 3 +- crystal/examples/files/append_to_file.cr | 4 +- crystal/examples/files/append_to_file_bug.cr | 2 +- crystal/examples/files/counter.cr | 6 +- crystal/examples/files/file_exists.cr | 9 +- crystal/examples/files/file_size.cr | 11 +- crystal/examples/files/modification_time.cr | 6 +- crystal/examples/files/multi_counter_json.cr | 29 ++- crystal/examples/files/multi_counter_yaml.cr | 25 ++- crystal/examples/files/read_from_file.cr | 6 +- crystal/examples/files/read_line_by_line.cr | 8 +- crystal/examples/files/read_lines.cr | 6 +- crystal/examples/files/write_to_file.cr | 4 +- crystal/examples/functions/array_overload.cr | 8 +- crystal/examples/functions/default_value.cr | 2 +- crystal/examples/functions/implicit.cr | 2 +- crystal/examples/functions/implicit_return.cr | 6 +- .../examples/functions/manually_separate.cr | 5 +- .../examples/functions/parameter_passing.cr | 2 +- crystal/examples/functions/parameter_types.cr | 8 +- ...pass_array_instead_of_individual_values.cr | 5 +- crystal/examples/functions/return_bool.cr | 7 +- crystal/examples/functions/return_value.cr | 2 +- crystal/examples/functions/tuple_from.cr | 5 +- crystal/examples/functions/type_or_nil.cr | 2 +- crystal/examples/functions/yield_block.cr | 2 - crystal/examples/functions/yield_both.cr | 1 - .../examples/functions/yield_parameters.cr | 3 +- crystal/examples/functions/yield_params.cr | 4 +- crystal/examples/gravatar.cr | 9 +- crystal/examples/hashes/count_words.cr | 14 +- .../hashes/empty_hash_string_int32.cr | 2 +- .../hashes/empty_hash_string_int32_bool.cr | 2 +- crystal/examples/hashes/get_value.cr | 5 +- crystal/examples/hashes/hash.cr | 12 +- crystal/examples/hashes/hash_and_types.cr | 5 +- crystal/examples/here_document.cr | 1 - crystal/examples/http_client.cr | 1 - crystal/examples/intro/cli.cr | 8 +- crystal/examples/intro/comments.cr | 2 - crystal/examples/intro/compound_types.cr | 12 +- crystal/examples/intro/debugging_print.cr | 8 +- crystal/examples/intro/deep_if.cr | 12 +- crystal/examples/intro/early_exit.cr | 2 +- crystal/examples/intro/elsif.cr | 6 +- crystal/examples/intro/float64_methods.cr | 4 +- crystal/examples/intro/hello_name.cr | 2 +- .../intro/hello_name_interpolation.cr | 2 +- crystal/examples/intro/hello_world.cr | 2 +- crystal/examples/intro/hello_world_print.cr | 2 +- crystal/examples/intro/if.cr | 4 +- crystal/examples/intro/int32_methods.cr | 8 +- crystal/examples/intro/numerical_operators.cr | 2 +- crystal/examples/intro/program_name.cr | 2 +- crystal/examples/intro/rectangle.cr | 4 +- crystal/examples/intro/true_values.cr | 14 +- crystal/examples/intro/types.cr | 10 +- crystal/examples/json/json.cr | 20 +- crystal/examples/json/json_to_array.cr | 5 +- crystal/examples/json/json_to_named_tuple.cr | 2 - crystal/examples/json/read_math_json.cr | 29 ++- crystal/examples/list_dir.cr | 8 +- crystal/examples/logging.cr | 2 +- crystal/examples/macros/function.cr | 2 - crystal/examples/methods.cr | 2 +- crystal/examples/mine.cr | 59 +++--- crystal/examples/multiple_assignments.cr | 9 +- crystal/examples/one/use_welcome.cr | 2 +- crystal/examples/one/welcome.cr | 4 +- crystal/examples/path_expand.cr | 3 +- crystal/examples/path_from_string.cr | 1 - crystal/examples/printf.cr | 8 +- crystal/examples/process.cr | 15 +- crystal/examples/raise_exception.cr | 13 +- crystal/examples/random/rand.cr | 4 +- crystal/examples/range/class_exclusive.cr | 2 +- crystal/examples/range/class_inclusive.cr | 2 +- crystal/examples/range/count.cr | 2 +- crystal/examples/range/exclusive_dots.cr | 2 +- crystal/examples/range/inclusive_dots.cr | 2 +- crystal/examples/range/loop_controls.cr | 2 +- crystal/examples/range/range_sum.cr | 2 +- crystal/examples/range/step.cr | 2 +- crystal/examples/regexes/match_slash.cr | 5 +- crystal/examples/sets/empty_set.cr | 3 +- crystal/examples/spaceship_operator.cr | 1 - crystal/examples/sqlite/all.cr | 17 +- crystal/examples/sqlite/in_memory.cr | 48 ++--- crystal/examples/sqlite/insert_exception.cr | 47 ++--- crystal/examples/sqlite/last_id.cr | 31 ++- .../examples/sqlite/multi_counter_sqlite.cr | 50 ++--- crystal/examples/sqlite/rows_affected.cr | 59 +++--- crystal/examples/sqlite/try_sqlite.cr | 7 +- crystal/examples/strings/convertable.cr | 23 +- crystal/examples/strings/empty_strings.cr | 1 - crystal/examples/strings/includes.cr | 1 - crystal/examples/strings/index.cr | 2 - crystal/examples/strings/reverse.cr | 1 - crystal/examples/strings/split_string.cr | 1 - crystal/examples/strings/starts_with.cr | 1 - crystal/examples/strings/string_iterator.cr | 8 +- crystal/examples/strings/substitute.cr | 4 +- crystal/examples/strings/substring.cr | 6 +- crystal/examples/strings/type_conversion.cr | 2 +- crystal/examples/struct/simple_struct.cr | 1 - .../struct/struct_with_initializer.cr | 2 +- crystal/examples/suffix_if.cr | 6 +- crystal/examples/suffix_unless.cr | 2 +- crystal/examples/symbols.cr | 26 +-- crystal/examples/system.cr | 2 +- crystal/examples/tempdir_function.cr | 25 +-- crystal/examples/test1/mymath.cr | 4 +- crystal/examples/test1/use_mymath.cr | 2 +- crystal/examples/time/add_timespan.cr | 1 - crystal/examples/time/elapsed_time.cr | 2 +- crystal/examples/time/time_difference.cr | 2 +- crystal/examples/time/types.cr | 1 - crystal/examples/traverse_tree.cr | 6 +- crystal/examples/try.cr | 17 +- crystal/examples/tuples/named_tuple_fields.cr | 6 +- crystal/examples/use_yaml.cr | 12 +- crystal/spec/demo_spec.cr | 2 +- crystal/spec/todo_spec.cr | 3 +- 161 files changed, 712 insertions(+), 805 deletions(-) diff --git a/crystal/examples/add_numbers.cr b/crystal/examples/add_numbers.cr index 25ae2dd24..f910abdd3 100644 --- a/crystal/examples/add_numbers.cr +++ b/crystal/examples/add_numbers.cr @@ -1,11 +1,11 @@ x = 23 y = 19 z = x + y -puts z # 42 -puts "#{x} + #{y} is #{z}" # 23 + 19 is 42 +puts z # 42 +puts "#{x} + #{y} is #{z}" # 23 + 19 is 42 a = "23" b = "19" c = a + b -puts c # 2319 -puts "#{a} + #{b} is #{c}" # 23 + 19 is 2319 +puts c # 2319 +puts "#{a} + #{b} is #{c}" # 23 + 19 is 2319 diff --git a/crystal/examples/arrays/array.cr b/crystal/examples/arrays/array.cr index 8d5c85129..d553fc570 100644 --- a/crystal/examples/arrays/array.cr +++ b/crystal/examples/arrays/array.cr @@ -1,14 +1,13 @@ planets = ["Mars", "Jupyter", "Saturn", "Earth"] -p! planets # ["Mars", "Jupyter", "Saturn", "Earth"] -puts typeof(planets) # Array(String) -puts planets.size # 4 +p! planets # ["Mars", "Jupyter", "Saturn", "Earth"] +puts typeof(planets) # Array(String) +puts planets.size # 4 integers = [3, 8, -2] -puts typeof(integers) # Array(Int32) +puts typeof(integers) # Array(Int32) floats = [3.14, 2.1] -puts typeof(floats) # Array(Float64) +puts typeof(floats) # Array(Float64) mixed = [1, 3.14, "PI"] -puts typeof(mixed) # Array(Float64 | Int32 | String) - +puts typeof(mixed) # Array(Float64 | Int32 | String) diff --git a/crystal/examples/arrays/array_iterate.cr b/crystal/examples/arrays/array_iterate.cr index 8b0d3ff79..ae5ca975a 100644 --- a/crystal/examples/arrays/array_iterate.cr +++ b/crystal/examples/arrays/array_iterate.cr @@ -1,8 +1,8 @@ planets = ["Mars", "Jupyter", "Saturn", "Earth"] -planets.each {|planet| puts planet} +planets.each { |planet| puts planet } # enumerate -planets.each_with_index {|planet, idx| - puts "#{idx}: #{planet}" +planets.each_with_index { |planet, idx| + puts "#{idx}: #{planet}" } diff --git a/crystal/examples/arrays/array_push.cr b/crystal/examples/arrays/array_push.cr index 41430eba3..d4e647685 100644 --- a/crystal/examples/arrays/array_push.cr +++ b/crystal/examples/arrays/array_push.cr @@ -2,7 +2,7 @@ planets = ["Mars", "Jupyter", "Saturn"] # append / push / << planets << "Pluto" -puts planets # ["Mars", "Jupyter", "Saturn", "Pluto"] +puts planets # ["Mars", "Jupyter", "Saturn", "Pluto"] planets.push("Venus") -puts planets # ["Mars", "Jupyter", "Saturn", "Pluto", "Venus"] +puts planets # ["Mars", "Jupyter", "Saturn", "Pluto", "Venus"] diff --git a/crystal/examples/arrays/count_digits.cr b/crystal/examples/arrays/count_digits.cr index c6c0382d3..bbd730082 100644 --- a/crystal/examples/arrays/count_digits.cr +++ b/crystal/examples/arrays/count_digits.cr @@ -1,10 +1,10 @@ text = "123456789112777" count = [0] * 10 -text.each_char {|chr| - count[chr.to_i] += 1 +text.each_char { |chr| + count[chr.to_i] += 1 } -count.each_with_index {|value, idx| - puts "#{idx} #{value}" +count.each_with_index { |value, idx| + puts "#{idx} #{value}" } diff --git a/crystal/examples/arrays/elements.cr b/crystal/examples/arrays/elements.cr index 9ac7be936..bf2683891 100644 --- a/crystal/examples/arrays/elements.cr +++ b/crystal/examples/arrays/elements.cr @@ -6,4 +6,3 @@ puts planets[-1] # Jupiter puts planets[0, 3] # ["Mercury", "Venus", "Earth"] puts planets[0..3] # ["Mercury", "Venus", "Earth", "Mars"] puts planets[0...3] # ["Mercury", "Venus", "Earth"] - diff --git a/crystal/examples/arrays/empty_array.cr b/crystal/examples/arrays/empty_array.cr index 46f9799f1..a07bc355b 100644 --- a/crystal/examples/arrays/empty_array.cr +++ b/crystal/examples/arrays/empty_array.cr @@ -1,17 +1,15 @@ # empty = [] # Syntax error - empty = [] of Int32 -puts empty.size # 0 -puts empty.empty? # true +puts empty.size # 0 +puts empty.empty? # true empty << 23 -puts empty.size # 1 -puts empty.empty? # false +puts empty.size # 1 +puts empty.empty? # false # empty << 3.14 # Error: no overload matches 'Array(Int32)#<<' with type Float64 other = Array(Int32).new -puts typeof(other) # Array(Int32) -puts other.size # 0 - +puts typeof(other) # Array(Int32) +puts other.size # 0 diff --git a/crystal/examples/arrays/filter.cr b/crystal/examples/arrays/filter.cr index 2d37f65a8..a7639c8d7 100644 --- a/crystal/examples/arrays/filter.cr +++ b/crystal/examples/arrays/filter.cr @@ -1,7 +1,11 @@ numbers = [10, 20, 7, 21, 5] puts numbers -small = numbers.reject do |num| num > 10 end +small = numbers.reject do |num| + num > 10 +end puts small -big = numbers.reject! do |num| num < 10 end +big = numbers.reject! do |num| + num < 10 +end puts big diff --git a/crystal/examples/arrays/map.cr b/crystal/examples/arrays/map.cr index e3fae9f70..087285a80 100644 --- a/crystal/examples/arrays/map.cr +++ b/crystal/examples/arrays/map.cr @@ -1,8 +1,9 @@ - numbers = [2, -3, 4, -5] puts numbers -doubles = numbers.map do |num| num*2 end +doubles = numbers.map do |num| + num*2 +end puts doubles triples = numbers.map { |num| num*3 } diff --git a/crystal/examples/assign_to_variable.cr b/crystal/examples/assign_to_variable.cr index 684e7764e..76b53ff15 100644 --- a/crystal/examples/assign_to_variable.cr +++ b/crystal/examples/assign_to_variable.cr @@ -5,4 +5,3 @@ p! typeof(x) x = 1 p! x p! typeof(x) - diff --git a/crystal/examples/backtick.cr b/crystal/examples/backtick.cr index 4a4fe34f3..0a15217cb 100644 --- a/crystal/examples/backtick.cr +++ b/crystal/examples/backtick.cr @@ -1,6 +1,6 @@ result = `ls -l` if $?.success? - puts result + puts result else - puts "Failure" -end \ No newline at end of file + puts "Failure" +end diff --git a/crystal/examples/capture.cr b/crystal/examples/capture.cr index 7d5f5c9ad..7bdaa9d74 100644 --- a/crystal/examples/capture.cr +++ b/crystal/examples/capture.cr @@ -1,4 +1,3 @@ - output, error, exit_code = capture("ls", ["-l", "-a"]) if exit_code == 0 puts output @@ -7,15 +6,14 @@ else end puts exit_code - def capture(cmd, params) process = Process.new(cmd, params, output: Process::Redirect::Pipe, error: Process::Redirect::Pipe, - ) + ) output = process.output.gets_to_end - error = process.error.gets_to_end + error = process.error.gets_to_end res = process.wait diff --git a/crystal/examples/capture2.cr b/crystal/examples/capture2.cr index 7dadce991..8c1ac7bee 100644 --- a/crystal/examples/capture2.cr +++ b/crystal/examples/capture2.cr @@ -1,12 +1,11 @@ output, error, exit_code = capture("ls", ["-l", "-a"]) if exit_code == 0 - puts output + puts output else - puts error + puts error end puts exit_code - def capture(cmd, params) stdout = IO::Memory.new stderr = IO::Memory.new diff --git a/crystal/examples/case.cr b/crystal/examples/case.cr index b4a46f847..37b4010bc 100644 --- a/crystal/examples/case.cr +++ b/crystal/examples/case.cr @@ -1,18 +1,17 @@ if ARGV.size != 1 - puts "Usage: case.cr DIRECTION" - exit -1 + puts "Usage: case.cr DIRECTION" + exit -1 end direction = ARGV[0] - case direction - when "forward" - puts "go on" - when "bacward" - puts "go back" - when "left", "right" - puts "go #{direction}" - else - puts "We don't know how to go '#{direction}'" - exit 0 +when "forward" + puts "go on" +when "bacward" + puts "go back" +when "left", "right" + puts "go #{direction}" +else + puts "We don't know how to go '#{direction}'" + exit 0 end diff --git a/crystal/examples/case_when_on_type.cr b/crystal/examples/case_when_on_type.cr index 6b887334c..905c141c0 100644 --- a/crystal/examples/case_when_on_type.cr +++ b/crystal/examples/case_when_on_type.cr @@ -17,4 +17,3 @@ when Int32 puts "int32" puts x.abs end - diff --git a/crystal/examples/catch_exception.cr b/crystal/examples/catch_exception.cr index 7d3087717..3f67d59cf 100644 --- a/crystal/examples/catch_exception.cr +++ b/crystal/examples/catch_exception.cr @@ -1,16 +1,15 @@ - filenames = ["README.md", "Other file", "crystal.json"] -filenames.each {|file| - begin - result = process(file) - puts result - rescue err - puts "Rescued! #{err.message}" - puts err.class # File::NotFoundError - end +filenames.each { |file| + begin + result = process(file) + puts result + rescue err + puts "Rescued! #{err.message}" + puts err.class # File::NotFoundError + end } def process(filename) - content = File.read(filename) - return content.size + content = File.read(filename) + return content.size end diff --git a/crystal/examples/check_slides.cr b/crystal/examples/check_slides.cr index 34ffdfe78..a7d8a307b 100644 --- a/crystal/examples/check_slides.cr +++ b/crystal/examples/check_slides.cr @@ -1,133 +1,131 @@ require "option_parser" + # Extract the list of imported files # Verify that all the files are indeed imported # Optionally verify that the same file is not imported more than once. class Options - class_property verbose = false + class_property verbose = false end - def main - get_options() - md_files = get_md_files(Dir.current) - if Options.verbose - puts "MD files:\n" - md_files.each {|path| - puts path - } - end - imported_files, errors = get_imported_files(md_files) - # imported_files.each {|file| - # puts file - # } - files = get_files(Dir.current) - # files.each {|name| - # puts name - #} - imported_files.each {|name| - if files.includes?(name) - files.delete name - else - puts "ERROR #{name} is imported but does not exist" - errors = true - end + get_options() + md_files = get_md_files(Dir.current) + if Options.verbose + puts "MD files:\n" + md_files.each { |path| + puts path } - files.each {|name| - puts "ERROR #{name} is not imported" - errors = true - } - - if errors - exit(1) + end + imported_files, errors = get_imported_files(md_files) + # imported_files.each {|file| + # puts file + # } + files = get_files(Dir.current) + # files.each {|name| + # puts name + # } + imported_files.each { |name| + if files.includes?(name) + files.delete name + else + puts "ERROR #{name} is imported but does not exist" + errors = true end + } + files.each { |name| + puts "ERROR #{name} is not imported" + errors = true + } + + if errors + exit(1) + end end def get_options - OptionParser.parse do |parser| - parser.banner = "Usage: check_slides.cr [arguments]" - parser.on("-v", "--verbose", "Verbose mode") { Options.verbose = true } - parser.on("-h", "--help", "Show this help") do - puts parser - exit - end - parser.invalid_option do |flag| - STDERR.puts "ERROR: #{flag} is not a valid option." - STDERR.puts parser - exit(1) - end - parser.missing_option do |flag| - STDERR.puts "ERROR: #{flag} requires a value" - STDERR.puts parser - exit(1) - end + OptionParser.parse do |parser| + parser.banner = "Usage: check_slides.cr [arguments]" + parser.on("-v", "--verbose", "Verbose mode") { Options.verbose = true } + parser.on("-h", "--help", "Show this help") do + puts parser + exit + end + parser.invalid_option do |flag| + STDERR.puts "ERROR: #{flag} is not a valid option." + STDERR.puts parser + exit(1) end + parser.missing_option do |flag| + STDERR.puts "ERROR: #{flag} requires a value" + STDERR.puts parser + exit(1) + end + end end - def get_imported_files(md_files) - imported_files = Set(String).new - errors = false - md_files.each{|path| - lines = File.read_lines(path) - lines.each {|line| - match = /^!\[\]\((.*)\)\s*$/.match(line) - if match - if ! imported_files.add?(match.[1]) - puts "WARN #{match.[1]} was imported twice" - errors = true - end - end - } + imported_files = Set(String).new + errors = false + md_files.each { |path| + lines = File.read_lines(path) + lines.each { |line| + match = /^!\[\]\((.*)\)\s*$/.match(line) + if match + if !imported_files.add?(match.[1]) + puts "WARN #{match.[1]} was imported twice" + errors = true + end + end } - return imported_files, errors + } + return imported_files, errors end - def get_files(root) - skip = Set{"Dockerfile", "shard.lock", "crystal.json"} - size = root.size - files = [] of String - all_files = Dir.glob("#{root}/**/*") - all_files.each {|path| - if ! File.file?(path) - next - end - short_name = path[size+1 ..] - if short_name.starts_with?("bin/") || short_name.starts_with?("lib/") - next - end - if short_name.ends_with?(".md") - next - end - if skip.any?(short_name) - next - end - files.push(short_name) - } - files.push(".ameba.yml") + skip = Set{"Dockerfile", "shard.lock", "crystal.json"} + size = root.size + files = [] of String + all_files = Dir.glob("#{root}/**/*") + all_files.each { |path| + if !File.file?(path) + next + end + short_name = path[size + 1..] + if short_name.starts_with?("bin/") || short_name.starts_with?("lib/") + next + end + if short_name.ends_with?(".md") + next + end + if skip.any?(short_name) + next + end + files.push(short_name) + } + files.push(".ameba.yml") - return files + return files end def get_md_files(root) - all_md_files = Dir.glob("#{root}/*.md") - md_files = [] of String + all_md_files = Dir.glob("#{root}/*.md") + md_files = [] of String - all_md_files.each {|path| - # TODO use some filter? - if path.ends_with?("README.md") - next - end - md_files.push(path) - } - return md_files + all_md_files.each { |path| + # TODO use some filter? + if path.ends_with?("README.md") + next + end + md_files.push(path) + } + return md_files end -#path = ARGV[0] +# path = ARGV[0] -#dr = Dir.glob("#{path}/**/*") -#dr.each {|name| puts name} +# dr = Dir.glob("#{path}/**/*") +# dr.each {|name| puts name} main() diff --git a/crystal/examples/classes/attribute_person.cr b/crystal/examples/classes/attribute_person.cr index e930625b8..4a374ce51 100644 --- a/crystal/examples/classes/attribute_person.cr +++ b/crystal/examples/classes/attribute_person.cr @@ -5,8 +5,8 @@ class Person end prs = Person.new(name: "Joe", height: 180) -puts prs # # -p! prs # prs # => # +puts prs # # +p! prs # prs # => # prs.email = "foo@bar.com" -p! prs # prs # => # +p! prs # prs # => # diff --git a/crystal/examples/classes/class_and_json.cr b/crystal/examples/classes/class_and_json.cr index 7b66b62f1..4510ad604 100644 --- a/crystal/examples/classes/class_and_json.cr +++ b/crystal/examples/classes/class_and_json.cr @@ -1,23 +1,22 @@ require "json" class Person - include JSON::Serializable + include JSON::Serializable - property name : String - property height : Float64 + property name : String + property height : Float64 - def initialize(@name, @height) - end + def initialize(@name, @height) + end end prs = Person.new(name: "Jane", height: 173.1) p! prs p! prs.to_json - george_str = %{{"name": "George", "height": 171.19}} -#details = JSON.parse(george_str) -#puts details +# details = JSON.parse(george_str) +# puts details prs = Person.from_json(george_str) p! prs @@ -26,9 +25,7 @@ puts prs.height puts typeof(prs.name) puts typeof(prs.height) - people_str = %{[{"name": "George", "height": 171.19}, {"name": "Jane", "height": 168.23}]} # details = JSON.parse(people_str) people = Array(Person).from_json(people_str) p! people - diff --git a/crystal/examples/classes/class_with_declared_getter.cr b/crystal/examples/classes/class_with_declared_getter.cr index b7f1a0009..0d5e00170 100644 --- a/crystal/examples/classes/class_with_declared_getter.cr +++ b/crystal/examples/classes/class_with_declared_getter.cr @@ -1,14 +1,14 @@ class Person - getter name : String + getter name : String - def initialize(name) - @name = name - end + def initialize(name) + @name = name + end end prs = Person.new(name: "Joe") -p! prs # prs # => # -puts prs.name # Joe +p! prs # prs # => # +puts prs.name # Joe # prs.name = "Jane" # Error: undefined method 'name=' for Person diff --git a/crystal/examples/classes/class_with_declared_getter_default.cr b/crystal/examples/classes/class_with_declared_getter_default.cr index 9fa0d2bd2..8fb8edc29 100644 --- a/crystal/examples/classes/class_with_declared_getter_default.cr +++ b/crystal/examples/classes/class_with_declared_getter_default.cr @@ -1,14 +1,14 @@ class Person - getter name : String + getter name : String - def initialize() - @name = "Default name" - end + def initialize + @name = "Default name" + end end prs = Person.new -p! prs # prs # => # -puts prs.name # Default name +p! prs # prs # => # +puts prs.name # Default name # prs.name = "Joe" # Error: undefined method 'name=' for Person diff --git a/crystal/examples/classes/class_with_default_property.cr b/crystal/examples/classes/class_with_default_property.cr index 5ca4dcb51..cfb9b7c9a 100644 --- a/crystal/examples/classes/class_with_default_property.cr +++ b/crystal/examples/classes/class_with_default_property.cr @@ -1,13 +1,13 @@ class Person - property name : String + property name : String - def initialize() - @name = "Default name" - end + def initialize + @name = "Default name" + end end prs = Person.new -p! prs # prs # => # -puts prs.name # Default name +p! prs # prs # => # +puts prs.name # Default name prs.name = "Joe" -puts prs.name # joe +puts prs.name # joe diff --git a/crystal/examples/classes/class_with_getters.cr b/crystal/examples/classes/class_with_getters.cr index 38e547f38..92f752f84 100644 --- a/crystal/examples/classes/class_with_getters.cr +++ b/crystal/examples/classes/class_with_getters.cr @@ -1,19 +1,18 @@ class Person - def initialize(name : String, height : Float64) - @name = name - @height = height - end + def initialize(name : String, height : Float64) + @name = name + @height = height + end - def name - @name - end + def name + @name + end end prs = Person.new(name: "Joe", height: 180) -puts prs # # -p! prs # prs # => # -puts prs.name # Joe - +puts prs # # +p! prs # prs # => # +puts prs.name # Joe # prs.name = "Jane" # Error: undefined method 'name=' for Person diff --git a/crystal/examples/classes/class_with_property.cr b/crystal/examples/classes/class_with_property.cr index be78f758d..a944bd6fc 100644 --- a/crystal/examples/classes/class_with_property.cr +++ b/crystal/examples/classes/class_with_property.cr @@ -1,15 +1,15 @@ class Person - property name : String + property name : String - def initialize(@name = "George") - end + def initialize(@name = "George") + end end prs = Person.new(name: "Joe") -p! prs # prs # => # -puts prs.name # Joe +p! prs # prs # => # +puts prs.name # Joe prs.name = "Jane" -puts prs.name # Jane +puts prs.name # Jane -defaulty = Person.new() +defaulty = Person.new puts defaulty.name # George diff --git a/crystal/examples/classes/class_with_setters.cr b/crystal/examples/classes/class_with_setters.cr index 04679c9a0..a46518f02 100644 --- a/crystal/examples/classes/class_with_setters.cr +++ b/crystal/examples/classes/class_with_setters.cr @@ -1,25 +1,24 @@ class Person - def initialize(name : String, height : Float64) - @name = name - @height = height - end + def initialize(name : String, height : Float64) + @name = name + @height = height + end - def name - @name - end - def name(value) - @name = value - end + def name + @name + end + def name(value) + @name = value + end end prs = Person.new(name: "Joe", height: 180) -puts prs # # -p! prs # prs # => # -puts prs.name # Joe - +puts prs # # +p! prs # prs # => # +puts prs.name # Joe prs.name("Jane") -p! prs # prs # => # -puts prs.name # Jane +p! prs # prs # => # +puts prs.name # Jane diff --git a/crystal/examples/classes/compare_objects.cr b/crystal/examples/classes/compare_objects.cr index cbcb751c3..17a39eb58 100644 --- a/crystal/examples/classes/compare_objects.cr +++ b/crystal/examples/classes/compare_objects.cr @@ -1,10 +1,10 @@ class Person - def_equals @name, @height - property name : String - property height : Float64 + def_equals @name, @height + property name : String + property height : Float64 - def initialize(@name, @height) - end + def initialize(@name, @height) + end end prs1 = Person.new(name: "Jane", height: 173.1) diff --git a/crystal/examples/classes/person.cr b/crystal/examples/classes/person.cr index ef39fa728..6a1fac780 100644 --- a/crystal/examples/classes/person.cr +++ b/crystal/examples/classes/person.cr @@ -1,7 +1,6 @@ class Person - def initialize(name : String, height : Float64) - @name = name - @height = height - end + def initialize(name : String, height : Float64) + @name = name + @height = height + end end - diff --git a/crystal/examples/classes/person_class.cr b/crystal/examples/classes/person_class.cr index 03b7699fd..6cc649d36 100644 --- a/crystal/examples/classes/person_class.cr +++ b/crystal/examples/classes/person_class.cr @@ -1,16 +1,16 @@ class Person - def initialize(name : String, height : Float64) - @name = name - @height = height - end + def initialize(name : String, height : Float64) + @name = name + @height = height + end end # prs = Person.new # Error: wrong number of arguments for 'Person.new' (given 0, expected 2) prs = Person.new(name: "Joe", height: 180) -puts prs # # -p! prs # prs # => # +puts prs # # +p! prs # prs # => # # puts prs.name # Error: undefined method 'name' for Person diff --git a/crystal/examples/classes/singleton_using_class_properties.cr b/crystal/examples/classes/singleton_using_class_properties.cr index 5982e731c..6328d0151 100644 --- a/crystal/examples/classes/singleton_using_class_properties.cr +++ b/crystal/examples/classes/singleton_using_class_properties.cr @@ -1,13 +1,12 @@ class Options - class_property repetition : Int32|Nil - class_property url = String - class_property verbose = Bool + class_property repetition : Int32 | Nil + class_property url = String + class_property verbose = Bool end puts Options.repetition Options.repetition = 3 puts Options.repetition -if ! Options.repetition.nil? - puts Options.repetition + 1 +if !Options.repetition.nil? + puts Options.repetition + 1 end - diff --git a/crystal/examples/classes/singleton_using_class_properties_with_defaults.cr b/crystal/examples/classes/singleton_using_class_properties_with_defaults.cr index 32ead782b..fd470b3bf 100644 --- a/crystal/examples/classes/singleton_using_class_properties_with_defaults.cr +++ b/crystal/examples/classes/singleton_using_class_properties_with_defaults.cr @@ -1,8 +1,9 @@ class Options - class_property repetition = 0 - class_property url = "" - class_property verbose = false + class_property repetition = 0 + class_property url = "" + class_property verbose = false end + puts Options.repetition Options.repetition = 3 puts Options.repetition diff --git a/crystal/examples/classes/use_person.cr b/crystal/examples/classes/use_person.cr index 26c893c57..5d82b0b58 100644 --- a/crystal/examples/classes/use_person.cr +++ b/crystal/examples/classes/use_person.cr @@ -1,14 +1,13 @@ require "./person" class Person - def name - return @name - end + def name + return @name + end end prs = Person.new(name: "Joe", height: 180) -puts prs # # -p! prs # prs # => # +puts prs # # +p! prs # prs # => # puts prs.name - diff --git a/crystal/examples/cli/argv.cr b/crystal/examples/cli/argv.cr index 9c8819931..ddf5ee2b7 100644 --- a/crystal/examples/cli/argv.cr +++ b/crystal/examples/cli/argv.cr @@ -1,5 +1,5 @@ puts ARGV puts ARGV.size -ARGV.each {|arg| - puts arg +ARGV.each { |arg| + puts arg } diff --git a/crystal/examples/cli/cli_parser.cr b/crystal/examples/cli/cli_parser.cr index 6c2892b61..6ec5612bf 100644 --- a/crystal/examples/cli/cli_parser.cr +++ b/crystal/examples/cli/cli_parser.cr @@ -24,6 +24,6 @@ OptionParser.parse do |parser| end if verbose - puts "Verbose mode" + puts "Verbose mode" end puts "Destination: #{destination}" diff --git a/crystal/examples/cli/parse_options.cr b/crystal/examples/cli/parse_options.cr index 09466b0ed..879ab2ebc 100644 --- a/crystal/examples/cli/parse_options.cr +++ b/crystal/examples/cli/parse_options.cr @@ -37,4 +37,3 @@ puts destination verbose, destination = get_params(["-v", "-d", "10.0.0.1"]) puts verbose puts destination - diff --git a/crystal/examples/cli/parsing_order.cr b/crystal/examples/cli/parsing_order.cr index 9757ed6a5..123ce260d 100644 --- a/crystal/examples/cli/parsing_order.cr +++ b/crystal/examples/cli/parsing_order.cr @@ -14,4 +14,3 @@ get_params([] of String) get_params(["-v"]) get_params(["-v", "-d", "10.0.0.1"]) get_params(["-d", "10.0.0.1", "-v"]) - diff --git a/crystal/examples/cli/some_program.cr b/crystal/examples/cli/some_program.cr index e541a2e7e..e6dc57b3f 100644 --- a/crystal/examples/cli/some_program.cr +++ b/crystal/examples/cli/some_program.cr @@ -1,6 +1,6 @@ if ARGV.size != 1 - puts "Usage: some_program FILENAME" - exit 1 + puts "Usage: some_program FILENAME" + exit 1 end filename = ARGV[0] diff --git a/crystal/examples/default.cr b/crystal/examples/default.cr index b40c5e1eb..f88825e71 100644 --- a/crystal/examples/default.cr +++ b/crystal/examples/default.cr @@ -5,4 +5,3 @@ puts ternary_name or_name = name || "default" puts or_name - diff --git a/crystal/examples/divide_by_zero.cr b/crystal/examples/divide_by_zero.cr index 699a3cd7c..e3cf8c665 100644 --- a/crystal/examples/divide_by_zero.cr +++ b/crystal/examples/divide_by_zero.cr @@ -1,8 +1,7 @@ - puts divide(8, 2) puts divide(8, 0) puts divide(8, 4) def divide(x, y) - return x/y -end \ No newline at end of file + return x/y +end diff --git a/crystal/examples/docspec/src/app.cr b/crystal/examples/docspec/src/app.cr index e91466103..c9d20b2d7 100644 --- a/crystal/examples/docspec/src/app.cr +++ b/crystal/examples/docspec/src/app.cr @@ -1,8 +1,7 @@ - # ``` # >> anagram?("abc", "bca") # => true # >> anagram?("abc", "abd") # => false # ``` def anagram?(x, y) - return x.split("").sort() == y.split("").sort() + return x.split("").sort == y.split("").sort end diff --git a/crystal/examples/files/append_to_file.cr b/crystal/examples/files/append_to_file.cr index a92ae9e13..da566b97d 100644 --- a/crystal/examples/files/append_to_file.cr +++ b/crystal/examples/files/append_to_file.cr @@ -1,6 +1,6 @@ if ARGV.size != 2 - puts "Need a filename and the content to write to it on the command line" - exit 1 + puts "Need a filename and the content to write to it on the command line" + exit 1 end filename, content = ARGV diff --git a/crystal/examples/files/append_to_file_bug.cr b/crystal/examples/files/append_to_file_bug.cr index 157eaafeb..39cec4f42 100644 --- a/crystal/examples/files/append_to_file_bug.cr +++ b/crystal/examples/files/append_to_file_bug.cr @@ -1 +1 @@ -File.write("out.txt", "content", mode="a") \ No newline at end of file +File.write("out.txt", "content", mode = "a") diff --git a/crystal/examples/files/counter.cr b/crystal/examples/files/counter.cr index 2b0b6c88a..4b3947b47 100644 --- a/crystal/examples/files/counter.cr +++ b/crystal/examples/files/counter.cr @@ -1,13 +1,11 @@ # if file exists read the content - filename = "counter.txt" - counter = 0 if File.exists?(filename) - content = File.read(filename) - counter = content.to_i + content = File.read(filename) + counter = content.to_i end counter += 1 diff --git a/crystal/examples/files/file_exists.cr b/crystal/examples/files/file_exists.cr index 585db29fd..c07472192 100644 --- a/crystal/examples/files/file_exists.cr +++ b/crystal/examples/files/file_exists.cr @@ -1,12 +1,11 @@ if ARGV.size != 1 - puts "Need a filename on the command line" - exit 1 + puts "Need a filename on the command line" + exit 1 end filename = ARGV[0] - if File.exists?(filename) - puts "Exists" + puts "Exists" else - puts "Does NOT exist" + puts "Does NOT exist" end diff --git a/crystal/examples/files/file_size.cr b/crystal/examples/files/file_size.cr index a03ac85f7..519b84fbd 100644 --- a/crystal/examples/files/file_size.cr +++ b/crystal/examples/files/file_size.cr @@ -1,13 +1,12 @@ if ARGV.size != 1 - puts "Need a filename on the command line" - exit 1 + puts "Need a filename on the command line" + exit 1 end filename = ARGV[0] if File.exists?(filename) - puts File.empty?(filename) - puts File.size(filename) + puts File.empty?(filename) + puts File.size(filename) else - puts "File #{filename} does not exist" + puts "File #{filename} does not exist" end - diff --git a/crystal/examples/files/modification_time.cr b/crystal/examples/files/modification_time.cr index ec2e3c867..8638c6d25 100644 --- a/crystal/examples/files/modification_time.cr +++ b/crystal/examples/files/modification_time.cr @@ -1,7 +1,7 @@ if ARGV.size != 1 - puts "Need a filename on the command line" - exit 1 + puts "Need a filename on the command line" + exit 1 end filename = ARGV[0] -puts File.info(filename).modification_time \ No newline at end of file +puts File.info(filename).modification_time diff --git a/crystal/examples/files/multi_counter_json.cr b/crystal/examples/files/multi_counter_json.cr index 3de8df5b1..e76c9a8ba 100644 --- a/crystal/examples/files/multi_counter_json.cr +++ b/crystal/examples/files/multi_counter_json.cr @@ -5,25 +5,20 @@ filename = "counter.json" # if file exists read the content counters = {} of String => Int32 if File.exists?(filename) - content = File.new(filename) - counters = Hash(String, Int32).from_json(content) + content = File.new(filename) + counters = Hash(String, Int32).from_json(content) end - if ARGV.size == 1 - name = ARGV[0] - if ! counters.has_key?(name) - counters[name] = 0 - end - counters[name] += 1 - puts counters[name] - File.write(filename, counters.to_json) + name = ARGV[0] + if !counters.has_key?(name) + counters[name] = 0 + end + counters[name] += 1 + puts counters[name] + File.write(filename, counters.to_json) else - counters.each {|arg, i| - puts "#{i}: #{arg}" - } + counters.each { |arg, i| + puts "#{i}: #{arg}" + } end - - - - diff --git a/crystal/examples/files/multi_counter_yaml.cr b/crystal/examples/files/multi_counter_yaml.cr index d429d722c..9babc0d27 100644 --- a/crystal/examples/files/multi_counter_yaml.cr +++ b/crystal/examples/files/multi_counter_yaml.cr @@ -4,21 +4,20 @@ filename = "counter.yaml" counters = {} of String => Int32 if File.exists?(filename) - content = File.new(filename) - counters = Hash(String, Int32).from_yaml(content) + content = File.new(filename) + counters = Hash(String, Int32).from_yaml(content) end - if ARGV.size == 1 - name = ARGV[0] - if ! counters.has_key?(name) - counters[name] = 0 - end - counters[name] += 1 - puts counters[name] - File.write(filename, counters.to_yaml) + name = ARGV[0] + if !counters.has_key?(name) + counters[name] = 0 + end + counters[name] += 1 + puts counters[name] + File.write(filename, counters.to_yaml) else - counters.each {|arg, i| - puts "#{i}: #{arg}" - } + counters.each { |arg, i| + puts "#{i}: #{arg}" + } end diff --git a/crystal/examples/files/read_from_file.cr b/crystal/examples/files/read_from_file.cr index 63f660590..40fb00de7 100644 --- a/crystal/examples/files/read_from_file.cr +++ b/crystal/examples/files/read_from_file.cr @@ -1,9 +1,9 @@ if ARGV.size != 1 - puts "Need a filename on the command line" - exit 1 + puts "Need a filename on the command line" + exit 1 end filename = ARGV[0] content = File.read(filename) -puts content \ No newline at end of file +puts content diff --git a/crystal/examples/files/read_line_by_line.cr b/crystal/examples/files/read_line_by_line.cr index 0ef42963e..8dbda8a42 100644 --- a/crystal/examples/files/read_line_by_line.cr +++ b/crystal/examples/files/read_line_by_line.cr @@ -1,9 +1,9 @@ if ARGV.size != 1 - puts "Need a filename on the command line" - exit 1 + puts "Need a filename on the command line" + exit 1 end filename = ARGV[0] -File.each_line(filename) {|line| - puts line +File.each_line(filename) { |line| + puts line } diff --git a/crystal/examples/files/read_lines.cr b/crystal/examples/files/read_lines.cr index c8b7fca06..0c3abc05c 100644 --- a/crystal/examples/files/read_lines.cr +++ b/crystal/examples/files/read_lines.cr @@ -1,9 +1,9 @@ if ARGV.size != 1 - puts "Need a filename on the command line" - exit 1 + puts "Need a filename on the command line" + exit 1 end filename = ARGV[0] content = File.read_lines(filename) -puts content \ No newline at end of file +puts content diff --git a/crystal/examples/files/write_to_file.cr b/crystal/examples/files/write_to_file.cr index cafd6ef6e..4eda64e3e 100644 --- a/crystal/examples/files/write_to_file.cr +++ b/crystal/examples/files/write_to_file.cr @@ -1,6 +1,6 @@ if ARGV.size != 2 - puts "Need a filename and the content to write to it on the command line" - exit 1 + puts "Need a filename and the content to write to it on the command line" + exit 1 end filename, content = ARGV diff --git a/crystal/examples/functions/array_overload.cr b/crystal/examples/functions/array_overload.cr index bc7c0d7fa..d3e73424f 100644 --- a/crystal/examples/functions/array_overload.cr +++ b/crystal/examples/functions/array_overload.cr @@ -1,10 +1,12 @@ def f(x, y) - return x + y + return x + y end + def f(args : Array(Int32)) - return f(args[0], args[1]) + return f(args[0], args[1]) end -puts f(2, 3) + +puts f(2, 3) values = [3, 4] puts values puts f(values) diff --git a/crystal/examples/functions/default_value.cr b/crystal/examples/functions/default_value.cr index 159023542..4118b84b7 100644 --- a/crystal/examples/functions/default_value.cr +++ b/crystal/examples/functions/default_value.cr @@ -1,5 +1,5 @@ def welcome(name = "World") - return "Hello #{name}!" + return "Hello #{name}!" end puts welcome diff --git a/crystal/examples/functions/implicit.cr b/crystal/examples/functions/implicit.cr index c3df944e7..e4ae45209 100644 --- a/crystal/examples/functions/implicit.cr +++ b/crystal/examples/functions/implicit.cr @@ -1,5 +1,5 @@ def add(x, y) - z = x + y + z = x + y end res = add(2, 3) diff --git a/crystal/examples/functions/implicit_return.cr b/crystal/examples/functions/implicit_return.cr index 3141f6be1..51a124d7f 100644 --- a/crystal/examples/functions/implicit_return.cr +++ b/crystal/examples/functions/implicit_return.cr @@ -4,7 +4,7 @@ def cond(x) end end -[3, 6].each{|value| +[3, 6].each { |value| puts value res = cond(value) puts res @@ -14,8 +14,6 @@ end # Error: undefined method '+' for Nil (compile-time type is (Int32 | Nil)) if !res.nil? - puts res+1 + puts res + 1 end } - - diff --git a/crystal/examples/functions/manually_separate.cr b/crystal/examples/functions/manually_separate.cr index d838afe5f..294f64ddd 100644 --- a/crystal/examples/functions/manually_separate.cr +++ b/crystal/examples/functions/manually_separate.cr @@ -1,7 +1,8 @@ def f(x, y) - return x + y + return x + y end -puts f(2, 3) + +puts f(2, 3) values = [3, 4] puts values diff --git a/crystal/examples/functions/parameter_passing.cr b/crystal/examples/functions/parameter_passing.cr index 706ecd1ea..fe5e22fb6 100644 --- a/crystal/examples/functions/parameter_passing.cr +++ b/crystal/examples/functions/parameter_passing.cr @@ -1,5 +1,5 @@ def welcome(name) - return "Hello #{name}!" + return "Hello #{name}!" end puts welcome("Foo") diff --git a/crystal/examples/functions/parameter_types.cr b/crystal/examples/functions/parameter_types.cr index bf78fdbdd..f4b2db09d 100644 --- a/crystal/examples/functions/parameter_types.cr +++ b/crystal/examples/functions/parameter_types.cr @@ -1,12 +1,14 @@ def welcome(name : String) - return "Hello #{name}" + return "Hello #{name}" end + puts welcome "Foo" + # puts welcome 42 # Error: no overload matches 'welcome' with type Int32 def add(x, y : Int32) - puts "#{x} #{y}" + puts "#{x} #{y}" end add(2, 3) @@ -14,4 +16,4 @@ add(2, 3) # add(2, 3.1) # Error: no overload matches 'add' with types Int32, Float64 -add(2.1, 3) # this works +add(2.1, 3) # this works diff --git a/crystal/examples/functions/pass_array_instead_of_individual_values.cr b/crystal/examples/functions/pass_array_instead_of_individual_values.cr index 3d936a196..95cbe562a 100644 --- a/crystal/examples/functions/pass_array_instead_of_individual_values.cr +++ b/crystal/examples/functions/pass_array_instead_of_individual_values.cr @@ -1,7 +1,8 @@ def f(x, y) - return x + y + return x + y end -puts f(2, 3) + +puts f(2, 3) values = [3, 4] puts values diff --git a/crystal/examples/functions/return_bool.cr b/crystal/examples/functions/return_bool.cr index 1ea325dd6..f7043f7f9 100644 --- a/crystal/examples/functions/return_bool.cr +++ b/crystal/examples/functions/return_bool.cr @@ -1,12 +1,13 @@ def is_odd(n : Int32) - return n % 2 == 1 + return n % 2 == 1 end + puts is_odd(3) puts is_odd(4) def is_this_odd?(n : Int32) - return n % 2 == 1 + return n % 2 == 1 end + puts is_this_odd?(3) puts is_this_odd?(4) - diff --git a/crystal/examples/functions/return_value.cr b/crystal/examples/functions/return_value.cr index e827b4c4b..788336b78 100644 --- a/crystal/examples/functions/return_value.cr +++ b/crystal/examples/functions/return_value.cr @@ -1,5 +1,5 @@ def welcome - return "Hello World!" + return "Hello World!" end puts welcome diff --git a/crystal/examples/functions/tuple_from.cr b/crystal/examples/functions/tuple_from.cr index 467199de6..463af7789 100644 --- a/crystal/examples/functions/tuple_from.cr +++ b/crystal/examples/functions/tuple_from.cr @@ -1,7 +1,8 @@ def f(x, y) - return x + y + return x + y end -puts f(2, 3) + +puts f(2, 3) values = [3, 4] puts values diff --git a/crystal/examples/functions/type_or_nil.cr b/crystal/examples/functions/type_or_nil.cr index 94fd61458..0d1af3327 100644 --- a/crystal/examples/functions/type_or_nil.cr +++ b/crystal/examples/functions/type_or_nil.cr @@ -16,6 +16,7 @@ def show(number : Int32) end show(23) + # show(nil) # Error: no overload matches 'show' with type Nil @@ -25,4 +26,3 @@ end other(23) other(nil) - diff --git a/crystal/examples/functions/yield_block.cr b/crystal/examples/functions/yield_block.cr index 18322fc77..6955493a3 100644 --- a/crystal/examples/functions/yield_block.cr +++ b/crystal/examples/functions/yield_block.cr @@ -7,5 +7,3 @@ end run { puts "in block" } - - diff --git a/crystal/examples/functions/yield_both.cr b/crystal/examples/functions/yield_both.cr index 49e772d38..f4b00549d 100644 --- a/crystal/examples/functions/yield_both.cr +++ b/crystal/examples/functions/yield_both.cr @@ -10,7 +10,6 @@ def bar puts "bar after" end - foo bar { puts "in block" } diff --git a/crystal/examples/functions/yield_parameters.cr b/crystal/examples/functions/yield_parameters.cr index 60901f784..0f357dbf1 100644 --- a/crystal/examples/functions/yield_parameters.cr +++ b/crystal/examples/functions/yield_parameters.cr @@ -4,7 +4,7 @@ def run(number, &block) puts "after" end -run(10) {|value| +run(10) { |value| puts "in block #{value}" } puts "----" @@ -12,4 +12,3 @@ puts "----" run(20) do |value| puts "in do-end #{value}" end - diff --git a/crystal/examples/functions/yield_params.cr b/crystal/examples/functions/yield_params.cr index 7b9060c9f..f3bf22ca2 100644 --- a/crystal/examples/functions/yield_params.cr +++ b/crystal/examples/functions/yield_params.cr @@ -4,7 +4,7 @@ def run puts "after" end -run {|value| +run { |value| puts "in block #{value}" } puts "----" @@ -14,7 +14,6 @@ run do |value| end puts "----" - run { puts "in block" } @@ -23,4 +22,3 @@ puts "----" run do puts "in do-end" end - diff --git a/crystal/examples/gravatar.cr b/crystal/examples/gravatar.cr index 18e88a752..48071b695 100644 --- a/crystal/examples/gravatar.cr +++ b/crystal/examples/gravatar.cr @@ -1,8 +1,8 @@ require "digest/md5" if ARGV.size != 1 - puts "Need EMAIL" - exit 1 + puts "Need EMAIL" + exit 1 end email = ARGV[0] @@ -10,8 +10,5 @@ code = gravatar(email) puts "https://www.gravatar.com/avatar/#{code}?s=100&d=blank" def gravatar(email) - return Digest::MD5.hexdigest(email) + return Digest::MD5.hexdigest(email) end - - - diff --git a/crystal/examples/hashes/count_words.cr b/crystal/examples/hashes/count_words.cr index 65d1b5a2a..bb3215779 100644 --- a/crystal/examples/hashes/count_words.cr +++ b/crystal/examples/hashes/count_words.cr @@ -1,13 +1,13 @@ words = ["cat", "dog", "snake", "cat", "bug", "ant", "cat", "dog"] count = {} of String => Int32 -words.each {|word| - if ! count.has_key?(word) - count[word] = 0 - end - count[word] += 1 +words.each { |word| + if !count.has_key?(word) + count[word] = 0 + end + count[word] += 1 } -count.each {|key, value| - puts "#{key} #{value}" +count.each { |key, value| + puts "#{key} #{value}" } diff --git a/crystal/examples/hashes/empty_hash_string_int32.cr b/crystal/examples/hashes/empty_hash_string_int32.cr index bc5282b73..11879157e 100644 --- a/crystal/examples/hashes/empty_hash_string_int32.cr +++ b/crystal/examples/hashes/empty_hash_string_int32.cr @@ -1,4 +1,4 @@ -phone_of = {} of String => String|Int32 +phone_of = {} of String => String | Int32 phone_of["Jane"] = "123" phone_of["Jack"] = "456" diff --git a/crystal/examples/hashes/empty_hash_string_int32_bool.cr b/crystal/examples/hashes/empty_hash_string_int32_bool.cr index 5a7e23db1..bd3a75177 100644 --- a/crystal/examples/hashes/empty_hash_string_int32_bool.cr +++ b/crystal/examples/hashes/empty_hash_string_int32_bool.cr @@ -1,4 +1,4 @@ -phone_of = {} of String => String|Int32|Bool +phone_of = {} of String => String | Int32 | Bool phone_of["Jane"] = "123" phone_of["Jack"] = "456" diff --git a/crystal/examples/hashes/get_value.cr b/crystal/examples/hashes/get_value.cr index 95f19e7a6..918e1dc3f 100644 --- a/crystal/examples/hashes/get_value.cr +++ b/crystal/examples/hashes/get_value.cr @@ -1,6 +1,6 @@ person = { - "name" => "Jane", - "number" => 42, + "name" => "Jane", + "number" => 42, } puts person @@ -15,4 +15,3 @@ puts name # Jane email = person["email"]? || "default@example.com" puts email.nil? # false puts email # default@example.com - diff --git a/crystal/examples/hashes/hash.cr b/crystal/examples/hashes/hash.cr index db5cd3cef..7db42f2e0 100644 --- a/crystal/examples/hashes/hash.cr +++ b/crystal/examples/hashes/hash.cr @@ -1,8 +1,8 @@ planets = { - "Mars" => 1, - "Jupyter" => 2, - "Saturn" => 3, - "Earth" => 4, + "Mars" => 1, + "Jupyter" => 2, + "Saturn" => 3, + "Earth" => 4, } puts planets puts planets.size @@ -10,8 +10,8 @@ puts planets.keys planets["Pluto"] = 7 -puts planets.each_key {|name| - puts "#{name}: #{planets[name]}" +puts planets.each_key { |name| + puts "#{name}: #{planets[name]}" } puts planets.has_key?("Pluto") diff --git a/crystal/examples/hashes/hash_and_types.cr b/crystal/examples/hashes/hash_and_types.cr index bf3b3bd77..5f51268f2 100644 --- a/crystal/examples/hashes/hash_and_types.cr +++ b/crystal/examples/hashes/hash_and_types.cr @@ -1,7 +1,6 @@ person = { - "name" => "Foo Bar", - "number" => 42, + "name" => "Foo Bar", + "number" => 42, } p! person puts typeof(person) # Hash(String, Int32 | String) - diff --git a/crystal/examples/here_document.cr b/crystal/examples/here_document.cr index 275426627..2ceb0ab43 100644 --- a/crystal/examples/here_document.cr +++ b/crystal/examples/here_document.cr @@ -7,4 +7,3 @@ Hello #{name} ANYTHING puts text - diff --git a/crystal/examples/http_client.cr b/crystal/examples/http_client.cr index b68baf315..ad2207374 100644 --- a/crystal/examples/http_client.cr +++ b/crystal/examples/http_client.cr @@ -5,7 +5,6 @@ response = HTTP::Client.get(url) puts response.status_code puts response.body - # Setting some values in the header url = "https://httpbin.org/get" response = HTTP::Client.get(url, headers: HTTP::Headers{"Key" => "Value"}) diff --git a/crystal/examples/intro/cli.cr b/crystal/examples/intro/cli.cr index 29f53db9f..9b0276639 100644 --- a/crystal/examples/intro/cli.cr +++ b/crystal/examples/intro/cli.cr @@ -1,10 +1,10 @@ puts ARGV puts ARGV.size -ARGV.each_with_index {|arg, i| - puts "Argument #{i} was #{arg}" +ARGV.each_with_index { |arg, i| + puts "Argument #{i} was #{arg}" } if ARGV.size > 0 - puts ARGV[0] -end \ No newline at end of file + puts ARGV[0] +end diff --git a/crystal/examples/intro/comments.cr b/crystal/examples/intro/comments.cr index db3e39f00..d7e9ae176 100644 --- a/crystal/examples/intro/comments.cr +++ b/crystal/examples/intro/comments.cr @@ -1,7 +1,5 @@ - # Some commented out code: # puts "hello" puts "crystal" # another comment - diff --git a/crystal/examples/intro/compound_types.cr b/crystal/examples/intro/compound_types.cr index ba20f6e90..703b49247 100644 --- a/crystal/examples/intro/compound_types.cr +++ b/crystal/examples/intro/compound_types.cr @@ -1,17 +1,17 @@ x = ["Foo", 42] -p! typeof(x) # typeof(x) # => Array(Int32 | String) +p! typeof(x) # typeof(x) # => Array(Int32 | String) a = {"Foo", 42} -p! typeof(a) # typeof(a) # => Tuple(String, Int32) +p! typeof(a) # typeof(a) # => Tuple(String, Int32) y = { "name" => "Foo Bar", - "id" => 42 + "id" => 42, } -p! typeof(y) # typeof(y) # => Hash(String, Int32 | String) +p! typeof(y) # typeof(y) # => Hash(String, Int32 | String) z = { "name": "Foo Bar", - "id": 42 + "id": 42, } -p! typeof(z) # typeof(z) # => NamedTuple(name: String, id: Int32) +p! typeof(z) # typeof(z) # => NamedTuple(name: String, id: Int32) diff --git a/crystal/examples/intro/debugging_print.cr b/crystal/examples/intro/debugging_print.cr index 62370066a..869a3a489 100644 --- a/crystal/examples/intro/debugging_print.cr +++ b/crystal/examples/intro/debugging_print.cr @@ -1,9 +1,9 @@ name = "Foo" person = { - name: "Foo", - number: 42, - yesno: true, - fruits: ["apple", "banana", "peach"], + name: "Foo", + number: 42, + yesno: true, + fruits: ["apple", "banana", "peach"], } puts name puts person diff --git a/crystal/examples/intro/deep_if.cr b/crystal/examples/intro/deep_if.cr index 7750ab3f2..28e92b4e6 100644 --- a/crystal/examples/intro/deep_if.cr +++ b/crystal/examples/intro/deep_if.cr @@ -1,11 +1,11 @@ age = 22 if age < 21 - puts "Sorry you cannot dring alcohol in the US." + puts "Sorry you cannot dring alcohol in the US." else - if 21 < age - puts "Can drink alcohol in the US as well." - else - puts "Congratulations on your birthday" - end + if 21 < age + puts "Can drink alcohol in the US as well." + else + puts "Congratulations on your birthday" + end end diff --git a/crystal/examples/intro/early_exit.cr b/crystal/examples/intro/early_exit.cr index 31f3c8477..06fcfb0b8 100644 --- a/crystal/examples/intro/early_exit.cr +++ b/crystal/examples/intro/early_exit.cr @@ -1,6 +1,6 @@ puts "before" answer = 42 if answer == 42 - exit 3 + exit 3 end puts "after" diff --git a/crystal/examples/intro/elsif.cr b/crystal/examples/intro/elsif.cr index 10443bc54..6c5beb8a7 100644 --- a/crystal/examples/intro/elsif.cr +++ b/crystal/examples/intro/elsif.cr @@ -1,9 +1,9 @@ age = 21 if age < 21 - puts "Sorry you cannot dring alcohol in the US." + puts "Sorry you cannot dring alcohol in the US." elsif 21 < age - puts "Can drink alcohol in the US as well." + puts "Can drink alcohol in the US as well." else - puts "Congratulations on your birthday" + puts "Congratulations on your birthday" end diff --git a/crystal/examples/intro/float64_methods.cr b/crystal/examples/intro/float64_methods.cr index c14c3f7ea..7b0c17184 100644 --- a/crystal/examples/intro/float64_methods.cr +++ b/crystal/examples/intro/float64_methods.cr @@ -1,4 +1,4 @@ x = -5.2 -p! x.abs # 5.2 -p! x.round # -5.0 +p! x.abs # 5.2 +p! x.round # -5.0 # p! x.even? # Undefined method even? for Float64 diff --git a/crystal/examples/intro/hello_name.cr b/crystal/examples/intro/hello_name.cr index 6da89faa8..809ef413c 100644 --- a/crystal/examples/intro/hello_name.cr +++ b/crystal/examples/intro/hello_name.cr @@ -1,3 +1,3 @@ name = "Foo Bar" print "Hello ", name, "!\n" -puts "Hello ", name, "!" \ No newline at end of file +puts "Hello ", name, "!" diff --git a/crystal/examples/intro/hello_name_interpolation.cr b/crystal/examples/intro/hello_name_interpolation.cr index 757066d71..8b9993e6f 100644 --- a/crystal/examples/intro/hello_name_interpolation.cr +++ b/crystal/examples/intro/hello_name_interpolation.cr @@ -1,2 +1,2 @@ name = "Foo Bar" -puts "Hello #{name}!" \ No newline at end of file +puts "Hello #{name}!" diff --git a/crystal/examples/intro/hello_world.cr b/crystal/examples/intro/hello_world.cr index 7f09b2f81..01a178ad4 100644 --- a/crystal/examples/intro/hello_world.cr +++ b/crystal/examples/intro/hello_world.cr @@ -1 +1 @@ -puts "Hello World!" \ No newline at end of file +puts "Hello World!" diff --git a/crystal/examples/intro/hello_world_print.cr b/crystal/examples/intro/hello_world_print.cr index d1c192139..050a216c7 100644 --- a/crystal/examples/intro/hello_world_print.cr +++ b/crystal/examples/intro/hello_world_print.cr @@ -1 +1 @@ -print "Hello World!\n" \ No newline at end of file +print "Hello World!\n" diff --git a/crystal/examples/intro/if.cr b/crystal/examples/intro/if.cr index 7beac3225..c63a79416 100644 --- a/crystal/examples/intro/if.cr +++ b/crystal/examples/intro/if.cr @@ -1,7 +1,7 @@ age = 22 if age < 21 - puts "Sorry you cannot dring alcohol in the US." + puts "Sorry you cannot dring alcohol in the US." else - puts "Can drink alcohol in the US as well." + puts "Can drink alcohol in the US as well." end diff --git a/crystal/examples/intro/int32_methods.cr b/crystal/examples/intro/int32_methods.cr index 3bac7f36b..295315b9e 100644 --- a/crystal/examples/intro/int32_methods.cr +++ b/crystal/examples/intro/int32_methods.cr @@ -1,5 +1,5 @@ -answer = -42 -p! answer.abs # 42 -p! answer.even? # true +answer = -42 +p! answer.abs # 42 +p! answer.even? # true -puts 42.gcd(35) # 7 ( Greatest common divisor ) +puts 42.gcd(35) # 7 ( Greatest common divisor ) diff --git a/crystal/examples/intro/numerical_operators.cr b/crystal/examples/intro/numerical_operators.cr index 22b9013f1..92dee812b 100644 --- a/crystal/examples/intro/numerical_operators.cr +++ b/crystal/examples/intro/numerical_operators.cr @@ -7,4 +7,4 @@ puts a * b # 14 puts a ** b # 49 (exponent) puts a / b # 3.5 puts a // b # 3 (floor division) -puts a % b # 1 (modulus) \ No newline at end of file +puts a % b # 1 (modulus) diff --git a/crystal/examples/intro/program_name.cr b/crystal/examples/intro/program_name.cr index 6e9ff2eaa..217ef90c4 100644 --- a/crystal/examples/intro/program_name.cr +++ b/crystal/examples/intro/program_name.cr @@ -1 +1 @@ -puts PROGRAM_NAME \ No newline at end of file +puts PROGRAM_NAME diff --git a/crystal/examples/intro/rectangle.cr b/crystal/examples/intro/rectangle.cr index 845afb5f5..10eec81d6 100644 --- a/crystal/examples/intro/rectangle.cr +++ b/crystal/examples/intro/rectangle.cr @@ -1,6 +1,6 @@ if ARGV.size != 2 - puts "Usage: #{PROGRAM_NAME} A B\nThe program needs two numbers, the two sides of the rectangle." - exit 1 + puts "Usage: #{PROGRAM_NAME} A B\nThe program needs two numbers, the two sides of the rectangle." + exit 1 end width, height = ARGV diff --git a/crystal/examples/intro/true_values.cr b/crystal/examples/intro/true_values.cr index 6cb2d0ae5..f7320278a 100644 --- a/crystal/examples/intro/true_values.cr +++ b/crystal/examples/intro/true_values.cr @@ -1,8 +1,8 @@ values = [0, "0", "", 1, true, false, nil] -values.each {|val| - if val - puts "#{val} is true" - else - puts "#{val} is NOT true" - end -} \ No newline at end of file +values.each { |val| + if val + puts "#{val} is true" + else + puts "#{val} is NOT true" + end +} diff --git a/crystal/examples/intro/types.cr b/crystal/examples/intro/types.cr index c256d013a..d7dce1bdd 100644 --- a/crystal/examples/intro/types.cr +++ b/crystal/examples/intro/types.cr @@ -1,13 +1,11 @@ name = "Foo Bar" -p! typeof(name) # typeof(name) => String +p! typeof(name) # typeof(name) => String age = 42 -p! typeof(age) # typeof(age) => Int32 +p! typeof(age) # typeof(age) => Int32 pi = 3.14 -p! typeof(pi) # typeof(pi) => Float64 +p! typeof(pi) # typeof(pi) => Float64 yesno = true -p! typeof(yesno) # typeof(yesno) # => Bool - - +p! typeof(yesno) # typeof(yesno) # => Bool diff --git a/crystal/examples/json/json.cr b/crystal/examples/json/json.cr index 22f52d0a8..340d79264 100644 --- a/crystal/examples/json/json.cr +++ b/crystal/examples/json/json.cr @@ -1,21 +1,19 @@ require "json" data = { - "Mars" => 1, - "Jupyter" => 2, - "Saturn" => 3, - "Earth" => 4, - "moons" => ["Our", "Jupyters"], - "missing" => nil + "Mars" => 1, + "Jupyter" => 2, + "Saturn" => 3, + "Earth" => 4, + "moons" => ["Our", "Jupyters"], + "missing" => nil, } -puts data # Hash(String, Array(String) | Int32 | Nil) +puts data # Hash(String, Array(String) | Int32 | Nil) json_string = data.to_json puts json_string parsed = JSON.parse(json_string) -puts parsed # JSON::Any +puts parsed # JSON::Any other = Hash(String, Array(String) | Int32 | Nil).from_json(json_string) -puts other.keys() - - +puts other.keys diff --git a/crystal/examples/json/json_to_array.cr b/crystal/examples/json/json_to_array.cr index 30858f411..665c78236 100644 --- a/crystal/examples/json/json_to_array.cr +++ b/crystal/examples/json/json_to_array.cr @@ -7,10 +7,9 @@ p! data # } # Error: undefined method 'each' for JSON::Any - things = Array(String).from_json(things_str) p! things -things.each {|thing| - puts thing +things.each { |thing| + puts thing } diff --git a/crystal/examples/json/json_to_named_tuple.cr b/crystal/examples/json/json_to_named_tuple.cr index 1e8e9f33e..64737015a 100644 --- a/crystal/examples/json/json_to_named_tuple.cr +++ b/crystal/examples/json/json_to_named_tuple.cr @@ -1,6 +1,5 @@ require "json" - alias Thing = NamedTuple(name: String, number: Int32) thing_json = %{{"name": "table", "number": 3}} @@ -8,4 +7,3 @@ puts thing_json tg = Thing.from_json(thing_json) puts tg - diff --git a/crystal/examples/json/read_math_json.cr b/crystal/examples/json/read_math_json.cr index 19d99da20..254587cc2 100644 --- a/crystal/examples/json/read_math_json.cr +++ b/crystal/examples/json/read_math_json.cr @@ -2,23 +2,22 @@ require "json" alias Constant = NamedTuple(name: String, value: Float64) alias MathResponseType = NamedTuple( - status: Int32, - status_text: String, - count: Int32, - results: Array(Constant) -) + status: Int32, + status_text: String, + count: Int32, + results: Array(Constant)) main -def main() - if ARGV.size != 1 - puts "Needs filename eg. math.json" - exit 1 - end - filename = ARGV[0] - content = File.read(filename) - data = MathResponseType.from_json(content) - puts data - puts data["results"][0].keys +def main + if ARGV.size != 1 + puts "Needs filename eg. math.json" + exit 1 + end + filename = ARGV[0] + content = File.read(filename) + data = MathResponseType.from_json(content) + puts data + puts data["results"][0].keys end # This will complain if field is missing or the value of a field is of incorrect type, diff --git a/crystal/examples/list_dir.cr b/crystal/examples/list_dir.cr index 74dd2e519..323bf63c5 100644 --- a/crystal/examples/list_dir.cr +++ b/crystal/examples/list_dir.cr @@ -1,11 +1,11 @@ if ARGV.size != 1 - puts "Needs path to directory" - exit 1 + puts "Needs path to directory" + exit 1 end path = ARGV[0] dr = Dir.new(path) -dr.children.each {|thing| - puts thing +dr.children.each { |thing| + puts thing } diff --git a/crystal/examples/logging.cr b/crystal/examples/logging.cr index aa7bb1730..184535a7a 100644 --- a/crystal/examples/logging.cr +++ b/crystal/examples/logging.cr @@ -8,4 +8,4 @@ Log.info { "Info level" } Log.notice { "Notice level" } Log.warn { "Warn level" } Log.error { "Error level" } -Log.fatal { "Fatal level" } \ No newline at end of file +Log.fatal { "Fatal level" } diff --git a/crystal/examples/macros/function.cr b/crystal/examples/macros/function.cr index ab534fd2e..ac104e41f 100644 --- a/crystal/examples/macros/function.cr +++ b/crystal/examples/macros/function.cr @@ -11,5 +11,3 @@ define_method foo, 1 puts "before foo" foo # => 1 puts "after foo" - - diff --git a/crystal/examples/methods.cr b/crystal/examples/methods.cr index cdfc0cff3..36fd6d9b9 100644 --- a/crystal/examples/methods.cr +++ b/crystal/examples/methods.cr @@ -1,5 +1,5 @@ class Object - macro methods + macro methods {{ @type.methods.map &.name.stringify }} end end diff --git a/crystal/examples/mine.cr b/crystal/examples/mine.cr index c5294205c..5713d96b3 100644 --- a/crystal/examples/mine.cr +++ b/crystal/examples/mine.cr @@ -2,47 +2,46 @@ require "http/client" require "json" - main def main - token = read_config - #get_page(token) - search(token) + token = read_config + # get_page(token) + search(token) end def read_config - config_file = "config.txt" - line = File.read_lines(config_file).first - #puts line - return line + config_file = "config.txt" + line = File.read_lines(config_file).first + # puts line + return line end def get_page(token) - url = "https://api.github.com/users/szabgab" - response = HTTP::Client.get(url, headers: HTTP::Headers{"AUthentication" => "token #{token}"}) + url = "https://api.github.com/users/szabgab" + response = HTTP::Client.get(url, headers: HTTP::Headers{"AUthentication" => "token #{token}"}) - puts response.status_code - puts response.body + puts response.status_code + puts response.body end def search(token) - per_page = 3 # max is 100 - query = "language:crystal" - page = 1 - sort = "updated" # stars, forks, help-wanted-issues, updated - order = "desc" - url = "https://api.github.com/search/repositories?q=#{query}&per_page=#{per_page}&page=#{page}&sort=#{sort}&order=#{order}" - response = HTTP::Client.get(url, headers: HTTP::Headers{"AUthentication" => "token #{token}"}) - #puts typeof(response) # HTTP::Client::Response - #puts typeof(response.body) # string - #data = Hash(String, Any).from_json(response.body) - json_text = response.body - puts json_text - #data = Hash(String, Bool | Array(Hash) | Int32 | Nil).from_json(json_text) - #puts typeof(data) - #puts data.keys - - #puts response.status_code - #puts response.body + per_page = 3 # max is 100 + query = "language:crystal" + page = 1 + sort = "updated" # stars, forks, help-wanted-issues, updated + order = "desc" + url = "https://api.github.com/search/repositories?q=#{query}&per_page=#{per_page}&page=#{page}&sort=#{sort}&order=#{order}" + response = HTTP::Client.get(url, headers: HTTP::Headers{"AUthentication" => "token #{token}"}) + # puts typeof(response) # HTTP::Client::Response + # puts typeof(response.body) # string + # data = Hash(String, Any).from_json(response.body) + json_text = response.body + puts json_text + # data = Hash(String, Bool | Array(Hash) | Int32 | Nil).from_json(json_text) + # puts typeof(data) + # puts data.keys + + # puts response.status_code + # puts response.body end diff --git a/crystal/examples/multiple_assignments.cr b/crystal/examples/multiple_assignments.cr index ccee865c7..0e4872f66 100644 --- a/crystal/examples/multiple_assignments.cr +++ b/crystal/examples/multiple_assignments.cr @@ -1,8 +1,7 @@ a, b = 2, 3 -puts a # 2 -puts b # 3 - +puts a # 2 +puts b # 3 a, b = b, a -puts a # 3 -puts b # 2 +puts a # 3 +puts b # 2 diff --git a/crystal/examples/one/use_welcome.cr b/crystal/examples/one/use_welcome.cr index 309f3cbe7..53804c090 100644 --- a/crystal/examples/one/use_welcome.cr +++ b/crystal/examples/one/use_welcome.cr @@ -1,2 +1,2 @@ require "./welcome.cr" -hi("Foo") \ No newline at end of file +hi("Foo") diff --git a/crystal/examples/one/welcome.cr b/crystal/examples/one/welcome.cr index fdebc55a4..049bf3ee1 100644 --- a/crystal/examples/one/welcome.cr +++ b/crystal/examples/one/welcome.cr @@ -1,3 +1,3 @@ def hi(name) - puts "Hello #{name}" -end \ No newline at end of file + puts "Hello #{name}" +end diff --git a/crystal/examples/path_expand.cr b/crystal/examples/path_expand.cr index 3dd643d6d..ad18383a5 100644 --- a/crystal/examples/path_expand.cr +++ b/crystal/examples/path_expand.cr @@ -2,6 +2,5 @@ some_path = "~/work" path = Path[some_path].expand(home: true) puts path - puts Path["~/other"].expand(home: true) -puts Path["~/other"].expand() +puts Path["~/other"].expand diff --git a/crystal/examples/path_from_string.cr b/crystal/examples/path_from_string.cr index 21d9fea35..bb1b40e99 100644 --- a/crystal/examples/path_from_string.cr +++ b/crystal/examples/path_from_string.cr @@ -1,3 +1,2 @@ path = Path["/home/foobar"] puts path - diff --git a/crystal/examples/printf.cr b/crystal/examples/printf.cr index 73573f5e8..82d06802d 100644 --- a/crystal/examples/printf.cr +++ b/crystal/examples/printf.cr @@ -1,13 +1,11 @@ - # Padding and Alignment number = 42 -printf "'%-4s'\n", number # Padding, left align -printf "'%4s'\n", number # Padding, right align -printf "'%04s'\n", number # Padding with 0s +printf "'%-4s'\n", number # Padding, left align +printf "'%4s'\n", number # Padding, right align +printf "'%04s'\n", number # Padding with 0s # Rounding floating point puts Math::PI printf "'%d'\n", Math::PI printf "'%f'\n", Math::PI printf "'%.3f'\n", Math::PI - diff --git a/crystal/examples/process.cr b/crystal/examples/process.cr index ed6d12b49..61ceaf7da 100644 --- a/crystal/examples/process.cr +++ b/crystal/examples/process.cr @@ -1,16 +1,15 @@ process = Process.new("ls", ["-l", "-a"], - output: Process::Redirect::Pipe, - error: Process::Redirect::Pipe, - ) + output: Process::Redirect::Pipe, + error: Process::Redirect::Pipe, +) output = process.output.gets_to_end -error = process.error.gets_to_end - +error = process.error.gets_to_end res = process.wait if res.success? - puts output + puts output else - puts error + puts error end -puts res.exit_status # exit code \ No newline at end of file +puts res.exit_status # exit code diff --git a/crystal/examples/raise_exception.cr b/crystal/examples/raise_exception.cr index a6861ce22..4386a38a8 100644 --- a/crystal/examples/raise_exception.cr +++ b/crystal/examples/raise_exception.cr @@ -1,12 +1,11 @@ - puts fibonacci(2) puts fibonacci(-1) puts fibonacci(3) def fibonacci(num) - if num < 0 - raise "Invalid number" - end - # ... - return num -end \ No newline at end of file + if num < 0 + raise "Invalid number" + end + # ... + return num +end diff --git a/crystal/examples/random/rand.cr b/crystal/examples/random/rand.cr index ddf49db9e..ef6aeefea 100644 --- a/crystal/examples/random/rand.cr +++ b/crystal/examples/random/rand.cr @@ -1,2 +1,2 @@ -puts Random.rand # floating point -puts Random.rand(6) # Int +puts Random.rand # floating point +puts Random.rand(6) # Int diff --git a/crystal/examples/range/class_exclusive.cr b/crystal/examples/range/class_exclusive.cr index 68c9381b4..737d87e57 100644 --- a/crystal/examples/range/class_exclusive.cr +++ b/crystal/examples/range/class_exclusive.cr @@ -1,4 +1,4 @@ r = Range.new(1, 3, exclusive: true) -r.each {|this| +r.each { |this| puts this } diff --git a/crystal/examples/range/class_inclusive.cr b/crystal/examples/range/class_inclusive.cr index 479156274..497f1d473 100644 --- a/crystal/examples/range/class_inclusive.cr +++ b/crystal/examples/range/class_inclusive.cr @@ -1,4 +1,4 @@ r = Range.new(1, 3) -r.each {|this| +r.each { |this| puts this } diff --git a/crystal/examples/range/count.cr b/crystal/examples/range/count.cr index 3770a9d64..399855c40 100644 --- a/crystal/examples/range/count.cr +++ b/crystal/examples/range/count.cr @@ -1,4 +1,4 @@ -res = (1..10).count{|ix| sprintf("%b", ix) == sprintf("%b", ix).reverse } +res = (1..10).count { |ix| sprintf("%b", ix) == sprintf("%b", ix).reverse } puts res # puts (1..10).map{|ix| sprintf("%b", ix) == sprintf("%b", ix).reverse; sprintf("%b", ix) } diff --git a/crystal/examples/range/exclusive_dots.cr b/crystal/examples/range/exclusive_dots.cr index a0514ed12..11af2a095 100644 --- a/crystal/examples/range/exclusive_dots.cr +++ b/crystal/examples/range/exclusive_dots.cr @@ -1,3 +1,3 @@ -(1...3).each {|this| +(1...3).each { |this| puts this } diff --git a/crystal/examples/range/inclusive_dots.cr b/crystal/examples/range/inclusive_dots.cr index fdfe9bdee..a92198eeb 100644 --- a/crystal/examples/range/inclusive_dots.cr +++ b/crystal/examples/range/inclusive_dots.cr @@ -1,3 +1,3 @@ -(1..3).each {|this| +(1..3).each { |this| puts this } diff --git a/crystal/examples/range/loop_controls.cr b/crystal/examples/range/loop_controls.cr index ec07610fc..1ce380650 100644 --- a/crystal/examples/range/loop_controls.cr +++ b/crystal/examples/range/loop_controls.cr @@ -1,4 +1,4 @@ -(1..10).each {|ix| +(1..10).each { |ix| next if ix % 2 == 0 break if ix == 7 puts ix diff --git a/crystal/examples/range/range_sum.cr b/crystal/examples/range/range_sum.cr index fd383cc66..07b7cd2d7 100644 --- a/crystal/examples/range/range_sum.cr +++ b/crystal/examples/range/range_sum.cr @@ -1,2 +1,2 @@ -res = (0..3).sum{|ix| ix * ix} +res = (0..3).sum { |ix| ix * ix } puts res diff --git a/crystal/examples/range/step.cr b/crystal/examples/range/step.cr index 2c8ee4ed2..9ee1355f6 100644 --- a/crystal/examples/range/step.cr +++ b/crystal/examples/range/step.cr @@ -1,3 +1,3 @@ -(1..10).step(3) {|ix| +(1..10).step(3) { |ix| puts ix } diff --git a/crystal/examples/regexes/match_slash.cr b/crystal/examples/regexes/match_slash.cr index 8f593cc4d..40655a2fa 100644 --- a/crystal/examples/regexes/match_slash.cr +++ b/crystal/examples/regexes/match_slash.cr @@ -1,11 +1,10 @@ text = "some/path" match = /\/(.*)/.match(text) if match - puts match.[1] + puts match.[1] end - match = %r{/(.*)}.match(text) if match - puts match.[1] + puts match.[1] end diff --git a/crystal/examples/sets/empty_set.cr b/crystal/examples/sets/empty_set.cr index 5db63562d..c37ffeb1f 100644 --- a/crystal/examples/sets/empty_set.cr +++ b/crystal/examples/sets/empty_set.cr @@ -1,7 +1,6 @@ -names = Set(String).new() +names = Set(String).new puts names.empty? names.add("Joe") puts names puts names.empty? - diff --git a/crystal/examples/spaceship_operator.cr b/crystal/examples/spaceship_operator.cr index 2e8a19ddb..9fdc7572a 100644 --- a/crystal/examples/spaceship_operator.cr +++ b/crystal/examples/spaceship_operator.cr @@ -5,4 +5,3 @@ puts 4 <=> 3 # 1 puts "a" <=> "a" # 0 puts "a" <=> "b" # -1 puts "b" <=> "a" # 1 - diff --git a/crystal/examples/sqlite/all.cr b/crystal/examples/sqlite/all.cr index 7c2c4d339..69a0dac00 100644 --- a/crystal/examples/sqlite/all.cr +++ b/crystal/examples/sqlite/all.cr @@ -10,7 +10,7 @@ def create_db(db_file) end begin DB.open "sqlite3://#{db_file}" do |db| - db.exec "CREATE TABLE information ( + db.exec "CREATE TABLE information ( id INTEGER PRIMARY KEY, name TEXT, isit BOOLEAN, @@ -26,7 +26,7 @@ def insert_data(db_file, name, isit, number) args = [name, isit, number] begin DB.open "sqlite3://#{db_file}" do |db| - db.exec "INSERT INTO information + db.exec "INSERT INTO information (name, isit, number) VALUES (?, ?, ?)", args: args end @@ -40,12 +40,9 @@ def get_max end def get_data(db_file) - DB.open "sqlite3://#{db_file}" do |db| - db.exec "SELECT * FROM information" - end - rescue err - puts "Exception #{err}" + DB.open "sqlite3://#{db_file}" do |db| + db.exec "SELECT * FROM information" + end +rescue err + puts "Exception #{err}" end - - - diff --git a/crystal/examples/sqlite/in_memory.cr b/crystal/examples/sqlite/in_memory.cr index b8fa7c76d..16ea2bf18 100644 --- a/crystal/examples/sqlite/in_memory.cr +++ b/crystal/examples/sqlite/in_memory.cr @@ -1,38 +1,38 @@ require "sqlite3" DB.open "sqlite3://%3Amemory%3A" do |db| - db.exec "CREATE TABLE data ( + db.exec "CREATE TABLE data ( id INTEGER PRIMARY KEY, name TEXT, yesno BOOLEAN, number INTEGER, start DATETIME )" - db.exec "INSERT INTO data (name, yesno, number, start) VALUES (?, ?, ?, ?)", - "Foo", true, 42, Time.utc - name = db.scalar "SELECT name FROM data" - puts name - puts typeof(name) - puts name.to_s + " and Bar" + db.exec "INSERT INTO data (name, yesno, number, start) VALUES (?, ?, ?, ?)", + "Foo", true, 42, Time.utc + name = db.scalar "SELECT name FROM data" + puts name + puts typeof(name) + puts name.to_s + " and Bar" - number = db.scalar "SELECT number FROM data" - puts number - puts typeof(number) - puts number.to_s.to_i + 1 + number = db.scalar "SELECT number FROM data" + puts number + puts typeof(number) + puts number.to_s.to_i + 1 - db.exec "INSERT INTO data (name, yesno, number, start) VALUES (?, ?, ?, ?)", - "Bar", false, 23, Time.utc - name = db.scalar "SELECT name FROM data" - puts name + db.exec "INSERT INTO data (name, yesno, number, start) VALUES (?, ?, ?, ?)", + "Bar", false, 23, Time.utc + name = db.scalar "SELECT name FROM data" + puts name - count = db.scalar "SELECT COUNT(*) FROM data" - puts count - puts typeof(count) + count = db.scalar "SELECT COUNT(*) FROM data" + puts count + puts typeof(count) - puts db.scalar "SELECT name FROM sqlite_schema" - db.query_all "SELECT name, type FROM sqlite_schema" do |line| - puts line - puts line.read - puts line.read - end + puts db.scalar "SELECT name FROM sqlite_schema" + db.query_all "SELECT name, type FROM sqlite_schema" do |line| + puts line + puts line.read + puts line.read + end end diff --git a/crystal/examples/sqlite/insert_exception.cr b/crystal/examples/sqlite/insert_exception.cr index 5068206bc..a73f96547 100644 --- a/crystal/examples/sqlite/insert_exception.cr +++ b/crystal/examples/sqlite/insert_exception.cr @@ -1,41 +1,40 @@ require "sqlite3" - db_file = "data.db" if File.exists?(db_file) - puts "File #{db_file} already exists. Aborting" - exit(1) + puts "File #{db_file} already exists. Aborting" + exit(1) end begin - DB.open "sqlite3://#{db_file}" do |db| - db.exec "CREATE TABLE contacts ( + DB.open "sqlite3://#{db_file}" do |db| + db.exec "CREATE TABLE contacts ( id INTEGER PRIMARY KEY, name TEXT, email TEXT, UNIQUE (name) )" - res = db.exec "INSERT INTO contacts (name, email) VALUES (?, ?)", "John Doe", "john@example.com" - puts typeof(res) # DB::ExecResult - puts res.rows_affected # 1 + res = db.exec "INSERT INTO contacts (name, email) VALUES (?, ?)", "John Doe", "john@example.com" + puts typeof(res) # DB::ExecResult + puts res.rows_affected # 1 - begin - res = db.exec "INSERT INTO contacts (name, email) VALUES (?, ?)", "John Doe", "john@example.com" - puts res.rows_affected - rescue err - puts "Exception #{err}" # SQLite3::Exception UNIQUE constraint failed: contacts.name - end + begin + res = db.exec "INSERT INTO contacts (name, email) VALUES (?, ?)", "John Doe", "john@example.com" + puts res.rows_affected + rescue err + puts "Exception #{err}" # SQLite3::Exception UNIQUE constraint failed: contacts.name + end - puts "contacts:" - db.query "SELECT id, name, email FROM contacts" do |rs| - puts "#{rs.column_name(0)} (#{rs.column_name(1)}) (#{rs.column_name(2)})" - rs.each do - puts "#{rs.read(Int64)} #{rs.read(String)} (#{rs.read(String)})" - end - end + puts "contacts:" + db.query "SELECT id, name, email FROM contacts" do |rs| + puts "#{rs.column_name(0)} (#{rs.column_name(1)}) (#{rs.column_name(2)})" + rs.each do + puts "#{rs.read(Int64)} #{rs.read(String)} (#{rs.read(String)})" + end end + end rescue err - puts "Exception #{err}" - # The external begin/rescue is needed because of this bug: - # https://github.com/crystal-lang/crystal-sqlite3/issues/52 + puts "Exception #{err}" + # The external begin/rescue is needed because of this bug: + # https://github.com/crystal-lang/crystal-sqlite3/issues/52 end diff --git a/crystal/examples/sqlite/last_id.cr b/crystal/examples/sqlite/last_id.cr index 20a1ada71..021e58aaa 100644 --- a/crystal/examples/sqlite/last_id.cr +++ b/crystal/examples/sqlite/last_id.cr @@ -1,30 +1,29 @@ require "sqlite3" - db_file = "data.db" if File.exists?(db_file) - puts "File #{db_file} already exists. Aborting" - exit(1) + puts "File #{db_file} already exists. Aborting" + exit(1) end DB.open "sqlite3://#{db_file}" do |db| - db.exec "CREATE TABLE contacts ( + db.exec "CREATE TABLE contacts ( id INTEGER PRIMARY KEY, name TEXT )" - res = db.exec "INSERT INTO contacts (name) VALUES (?)", "John Doe" - puts res.rows_affected - puts res.last_insert_id + res = db.exec "INSERT INTO contacts (name) VALUES (?)", "John Doe" + puts res.rows_affected + puts res.last_insert_id - res = db.exec "INSERT INTO contacts (name) VALUES (?)", "Jane Doe" - puts res.rows_affected - puts res.last_index_id + res = db.exec "INSERT INTO contacts (name) VALUES (?)", "Jane Doe" + puts res.rows_affected + puts res.last_index_id - puts "contacts:" - db.query "SELECT id, name FROM contacts" do |rs| - puts "#{rs.column_name(0)} (#{rs.column_name(1)})" - rs.each do - puts "#{rs.read(Int64)} #{rs.read(String)}" - end + puts "contacts:" + db.query "SELECT id, name FROM contacts" do |rs| + puts "#{rs.column_name(0)} (#{rs.column_name(1)})" + rs.each do + puts "#{rs.read(Int64)} #{rs.read(String)}" end + end end diff --git a/crystal/examples/sqlite/multi_counter_sqlite.cr b/crystal/examples/sqlite/multi_counter_sqlite.cr index 6c9844c26..e84cbb838 100644 --- a/crystal/examples/sqlite/multi_counter_sqlite.cr +++ b/crystal/examples/sqlite/multi_counter_sqlite.cr @@ -1,36 +1,36 @@ require "sqlite3" db_file = "counter.db" -if ! File.exists?(db_file) - DB.open "sqlite3://#{db_file}" do |db| - db.exec "CREATE TABLE counters (name TEXT, count INTEGER, UNIQUE(name))" - end +if !File.exists?(db_file) + DB.open "sqlite3://#{db_file}" do |db| + db.exec "CREATE TABLE counters (name TEXT, count INTEGER, UNIQUE(name))" + end end DB.open "sqlite3://#{db_file}" do |db| - if ARGV.size == 1 - name = ARGV[0] - count = 0 - db.query "SELECT count FROM counters WHERE name=?", name do |rs| - rs.each do - count = rs.read(Int32) - end - end + if ARGV.size == 1 + name = ARGV[0] + count = 0 + db.query "SELECT count FROM counters WHERE name=?", name do |rs| + rs.each do + count = rs.read(Int32) + end + end - count += 1 - puts count + count += 1 + puts count - if count == 1 - db.exec "INSERT INTO counters VALUES (?, ?)", name, count - else - db.exec "UPDATE counters SET count=? WHERE name=?", count, name - end + if count == 1 + db.exec "INSERT INTO counters VALUES (?, ?)", name, count else - db.query "SELECT name, count FROM counters ORDER BY name DESC" do |rs| - puts "#{rs.column_name(0)} (#{rs.column_name(1)})" - rs.each do - puts "#{rs.read(String)} (#{rs.read(Int32)})" - end - end + db.exec "UPDATE counters SET count=? WHERE name=?", count, name + end + else + db.query "SELECT name, count FROM counters ORDER BY name DESC" do |rs| + puts "#{rs.column_name(0)} (#{rs.column_name(1)})" + rs.each do + puts "#{rs.read(String)} (#{rs.read(Int32)})" + end end + end end diff --git a/crystal/examples/sqlite/rows_affected.cr b/crystal/examples/sqlite/rows_affected.cr index 6c0547099..aec5daec2 100644 --- a/crystal/examples/sqlite/rows_affected.cr +++ b/crystal/examples/sqlite/rows_affected.cr @@ -1,46 +1,43 @@ require "sqlite3" - db_file = "data.db" if File.exists?(db_file) - puts "File #{db_file} already exists. Aborting" - exit(1) + puts "File #{db_file} already exists. Aborting" + exit(1) end begin - DB.open "sqlite3://#{db_file}" do |db| - db.exec "CREATE TABLE contacts ( + DB.open "sqlite3://#{db_file}" do |db| + db.exec "CREATE TABLE contacts ( id INTEGER PRIMARY KEY, name TEXT, email TEXT, UNIQUE (name) )" - res = db.exec "INSERT INTO contacts (name, email) VALUES (?, ?)", "John Doe", "john@example.com" - puts res.rows_affected # 1 - res = db.exec "INSERT INTO contacts (name, email) VALUES (?, ?)", "Other Person", "other@example.com" - puts res.rows_affected # 1 - - - res = db.exec "UPDATE contacts SET email=? WHERE name=?", "john.doe@example.com", "John Doe" - puts res.rows_affected # 1 - - res = db.exec "UPDATE contacts SET email=? WHERE name=?", "john.doe@example.com", "No such user" - puts res.rows_affected # 0 - - res = db.exec "UPDATE contacts SET email=?", "shared@example.com" - puts res.rows_affected # 2 - - - puts "contacts:" - db.query "SELECT id, name, email FROM contacts" do |rs| - puts "#{rs.column_name(0)} (#{rs.column_name(1)}) (#{rs.column_name(2)})" - rs.each do - puts "#{rs.read(Int64)} #{rs.read(String)} (#{rs.read(String)})" - end - end + res = db.exec "INSERT INTO contacts (name, email) VALUES (?, ?)", "John Doe", "john@example.com" + puts res.rows_affected # 1 + res = db.exec "INSERT INTO contacts (name, email) VALUES (?, ?)", "Other Person", "other@example.com" + puts res.rows_affected # 1 + + res = db.exec "UPDATE contacts SET email=? WHERE name=?", "john.doe@example.com", "John Doe" + puts res.rows_affected # 1 + + res = db.exec "UPDATE contacts SET email=? WHERE name=?", "john.doe@example.com", "No such user" + puts res.rows_affected # 0 + + res = db.exec "UPDATE contacts SET email=?", "shared@example.com" + puts res.rows_affected # 2 + + puts "contacts:" + db.query "SELECT id, name, email FROM contacts" do |rs| + puts "#{rs.column_name(0)} (#{rs.column_name(1)}) (#{rs.column_name(2)})" + rs.each do + puts "#{rs.read(Int64)} #{rs.read(String)} (#{rs.read(String)})" + end end + end rescue err - puts "Exception #{err}" - # The external begin/rescue is needed because of this bug: - # https://github.com/crystal-lang/crystal-sqlite3/issues/52 + puts "Exception #{err}" + # The external begin/rescue is needed because of this bug: + # https://github.com/crystal-lang/crystal-sqlite3/issues/52 end diff --git a/crystal/examples/sqlite/try_sqlite.cr b/crystal/examples/sqlite/try_sqlite.cr index 04b06c1f3..e0c161173 100644 --- a/crystal/examples/sqlite/try_sqlite.cr +++ b/crystal/examples/sqlite/try_sqlite.cr @@ -1,11 +1,10 @@ require "sqlite3" - # Based on the example in the documentation db_file = "data.db" if File.exists?(db_file) - puts "File #{db_file} already exists. Aborting" - exit(1) + puts "File #{db_file} already exists. Aborting" + exit(1) end DB.open "sqlite3://#{db_file}" do |db| db.exec "CREATE TABLE contacts (name TEXT, age INTEGER)" @@ -29,4 +28,4 @@ DB.open "sqlite3://#{db_file}" do |db| # => John Doe (30) end end -end \ No newline at end of file +end diff --git a/crystal/examples/strings/convertable.cr b/crystal/examples/strings/convertable.cr index dbaa671e1..cf6f6355c 100644 --- a/crystal/examples/strings/convertable.cr +++ b/crystal/examples/strings/convertable.cr @@ -1,15 +1,14 @@ values = ["42", "42.1", "abc", "0"] -values.each {|val| - puts val - puts val.to_i? - if val.to_i? - puts "Convertable to Int32" - end +values.each { |val| + puts val + puts val.to_i? + if val.to_i? + puts "Convertable to Int32" + end - puts val.to_f? - if val.to_f? - puts "Convertable to Floar64" - end - puts "---" + puts val.to_f? + if val.to_f? + puts "Convertable to Floar64" + end + puts "---" } - diff --git a/crystal/examples/strings/empty_strings.cr b/crystal/examples/strings/empty_strings.cr index 05911d055..7f7488861 100644 --- a/crystal/examples/strings/empty_strings.cr +++ b/crystal/examples/strings/empty_strings.cr @@ -7,4 +7,3 @@ whitespaces = " \t\n\n\t" puts whitespaces.size puts whitespaces.empty? puts whitespaces.blank? - diff --git a/crystal/examples/strings/includes.cr b/crystal/examples/strings/includes.cr index d3403a3a0..cf7dadff3 100644 --- a/crystal/examples/strings/includes.cr +++ b/crystal/examples/strings/includes.cr @@ -2,4 +2,3 @@ text = "The black cat climbed the green tree" puts text.includes?("cat") puts text.includes?("dog") - diff --git a/crystal/examples/strings/index.cr b/crystal/examples/strings/index.cr index 9e1b2c03a..857d526a6 100644 --- a/crystal/examples/strings/index.cr +++ b/crystal/examples/strings/index.cr @@ -5,5 +5,3 @@ puts text.index("dog") puts text.index("c") puts text.rindex("c") - - diff --git a/crystal/examples/strings/reverse.cr b/crystal/examples/strings/reverse.cr index 880294887..207c3810f 100644 --- a/crystal/examples/strings/reverse.cr +++ b/crystal/examples/strings/reverse.cr @@ -4,4 +4,3 @@ rev = text.reverse puts rev puts text puts rev.reverse - diff --git a/crystal/examples/strings/split_string.cr b/crystal/examples/strings/split_string.cr index a5457121b..bfbd86c70 100644 --- a/crystal/examples/strings/split_string.cr +++ b/crystal/examples/strings/split_string.cr @@ -6,7 +6,6 @@ puts pieces # ["This", "is", "a", "", "string"] pieces = text.split(/ +/) puts pieces # ["This", "is", "a", "string"] - text = "name:secret" name, password = text.split(":") puts name diff --git a/crystal/examples/strings/starts_with.cr b/crystal/examples/strings/starts_with.cr index 1e2b22fec..d411dc14d 100644 --- a/crystal/examples/strings/starts_with.cr +++ b/crystal/examples/strings/starts_with.cr @@ -1,4 +1,3 @@ text = "The black cat climbed the green tree" puts text.starts_with?("The") puts text.starts_with?("the") - diff --git a/crystal/examples/strings/string_iterator.cr b/crystal/examples/strings/string_iterator.cr index e8061315c..d0fa0fd64 100644 --- a/crystal/examples/strings/string_iterator.cr +++ b/crystal/examples/strings/string_iterator.cr @@ -1,5 +1,5 @@ -text = "Crystal" # STring -text.each_char {|chr| - puts chr # Char - puts chr.to_s # String +text = "Crystal" # STring +text.each_char { |chr| + puts chr # Char + puts chr.to_s # String } diff --git a/crystal/examples/strings/substitute.cr b/crystal/examples/strings/substitute.cr index 32ef16468..786f8f051 100644 --- a/crystal/examples/strings/substitute.cr +++ b/crystal/examples/strings/substitute.cr @@ -14,7 +14,7 @@ puts text puts new_text animal = "cat" -new_text = text.sub animal, do |original| - original.upcase +new_text = text.sub animal do |original| + original.upcase end puts new_text diff --git a/crystal/examples/strings/substring.cr b/crystal/examples/strings/substring.cr index 0dc17e390..c013a97ca 100644 --- a/crystal/examples/strings/substring.cr +++ b/crystal/examples/strings/substring.cr @@ -2,9 +2,7 @@ text = "The black cat climbed the green tree" puts text[0] puts text[4] -puts text[0, 4] # 4 characters (start, count) -puts text[0..4] # 5 characters (Range) +puts text[0, 4] # 4 characters (start, count) +puts text[0..4] # 5 characters (Range) # count cannot be negative, but the Range ending can and it means, from the end of the string puts text[0..-4] - - diff --git a/crystal/examples/strings/type_conversion.cr b/crystal/examples/strings/type_conversion.cr index 979d2b20e..7888e8799 100644 --- a/crystal/examples/strings/type_conversion.cr +++ b/crystal/examples/strings/type_conversion.cr @@ -6,4 +6,4 @@ p! value.to_f value = "42" puts value.to_i -p! value.to_i \ No newline at end of file +p! value.to_i diff --git a/crystal/examples/struct/simple_struct.cr b/crystal/examples/struct/simple_struct.cr index 2fff7de2f..bb2c0be4d 100644 --- a/crystal/examples/struct/simple_struct.cr +++ b/crystal/examples/struct/simple_struct.cr @@ -11,4 +11,3 @@ puts cfg cfg.address = "foo@bar.com" puts cfg - diff --git a/crystal/examples/struct/struct_with_initializer.cr b/crystal/examples/struct/struct_with_initializer.cr index a13adb158..04c5a310c 100644 --- a/crystal/examples/struct/struct_with_initializer.cr +++ b/crystal/examples/struct/struct_with_initializer.cr @@ -1,6 +1,7 @@ struct MyConfig property name : String? property address : String? + def initialize(@name) end end @@ -13,4 +14,3 @@ puts cfg cfg.address = "foo@bar.com" puts cfg - diff --git a/crystal/examples/suffix_if.cr b/crystal/examples/suffix_if.cr index 07ab8ecae..e43f5658b 100644 --- a/crystal/examples/suffix_if.cr +++ b/crystal/examples/suffix_if.cr @@ -2,6 +2,6 @@ x = 23 puts "OK" if x > 20 puts "OK" if x != 20 -begin x = x+1; puts x end if x < 30 - - +begin + x = x + 1; puts x +end if x < 30 diff --git a/crystal/examples/suffix_unless.cr b/crystal/examples/suffix_unless.cr index 2f63b7da1..9eb10dfc4 100644 --- a/crystal/examples/suffix_unless.cr +++ b/crystal/examples/suffix_unless.cr @@ -1,4 +1,4 @@ x = 23 puts "not 17" unless x == 17 -puts "not 17" if !( x == 17) +puts "not 17" if !(x == 17) puts "not 17" if x != 17 diff --git a/crystal/examples/symbols.cr b/crystal/examples/symbols.cr index 15262093d..70c3e53ab 100644 --- a/crystal/examples/symbols.cr +++ b/crystal/examples/symbols.cr @@ -1,11 +1,11 @@ -#:pi = 3.14 +# :pi = 3.14 values = { - "foo" => 1, - "bar" => 2, - "baz" => 3, + "foo" => 1, + "bar" => 2, + "baz" => 3, } -#puts :pi +# puts :pi names = %i(foo bar baz) puts names puts names[0] @@ -13,13 +13,13 @@ puts typeof(names) puts typeof(names[0]) puts values -#names.each {|name| +# names.each {|name| # puts name # values[name] -#} +# } h = { - "fname" => "Foo", + "fname" => "Foo", } puts h puts typeof(h) @@ -28,20 +28,16 @@ puts h # puts h[:lname] # Missing hash key: :lname (KeyError) - # g and i are the same i = { - :fname => "Foo" + :fname => "Foo", } puts i puts typeof(i) -#i["fname"] +# i["fname"] puts i[:fname] g = { - fname: "Foo", # Symbol + fname: "Foo", # Symbol } puts g[:fname] - - - diff --git a/crystal/examples/system.cr b/crystal/examples/system.cr index 35b8a8b12..f910ee671 100644 --- a/crystal/examples/system.cr +++ b/crystal/examples/system.cr @@ -1,2 +1,2 @@ res = system("ls -l") -puts res \ No newline at end of file +puts res diff --git a/crystal/examples/tempdir_function.cr b/crystal/examples/tempdir_function.cr index 069766687..f79102d01 100644 --- a/crystal/examples/tempdir_function.cr +++ b/crystal/examples/tempdir_function.cr @@ -1,22 +1,19 @@ require "file_utils" - tempdir(cleanup: true) do |tmp_dir| - puts tmp_dir - path = Path.new(tmp_dir, "welcome.txt") - File.write(path, "Hello World") + puts tmp_dir + path = Path.new(tmp_dir, "welcome.txt") + File.write(path, "Hello World") end - def tempdir(cleanup = true) - tmp_dir = File.tempname - begin - FileUtils.mkdir(tmp_dir) - yield tmp_dir - ensure - if cleanup - FileUtils.rm_rf(tmp_dir) - end + tmp_dir = File.tempname + begin + FileUtils.mkdir(tmp_dir) + yield tmp_dir + ensure + if cleanup + FileUtils.rm_rf(tmp_dir) end + end end - diff --git a/crystal/examples/test1/mymath.cr b/crystal/examples/test1/mymath.cr index 3224ff5c4..4163b0464 100644 --- a/crystal/examples/test1/mymath.cr +++ b/crystal/examples/test1/mymath.cr @@ -1,3 +1,3 @@ def add(x, y) - return x * y -end \ No newline at end of file + return x * y +end diff --git a/crystal/examples/test1/use_mymath.cr b/crystal/examples/test1/use_mymath.cr index e99656465..e36332bfb 100644 --- a/crystal/examples/test1/use_mymath.cr +++ b/crystal/examples/test1/use_mymath.cr @@ -1,2 +1,2 @@ require "./mymath.cr" -puts add(2, 2) \ No newline at end of file +puts add(2, 2) diff --git a/crystal/examples/time/add_timespan.cr b/crystal/examples/time/add_timespan.cr index 8d4398944..eeb6ed12a 100644 --- a/crystal/examples/time/add_timespan.cr +++ b/crystal/examples/time/add_timespan.cr @@ -2,4 +2,3 @@ now = Time.utc tomorrow = now + Time::Span.new(days: 1) puts now puts tomorrow - diff --git a/crystal/examples/time/elapsed_time.cr b/crystal/examples/time/elapsed_time.cr index 552c5cc13..9b631607f 100644 --- a/crystal/examples/time/elapsed_time.cr +++ b/crystal/examples/time/elapsed_time.cr @@ -2,7 +2,7 @@ t0 = Time.monotonic sleep 1 t1 = Time.monotonic -elapsed = t1-t0 +elapsed = t1 - t0 puts elapsed puts elapsed.seconds puts elapsed.total_seconds diff --git a/crystal/examples/time/time_difference.cr b/crystal/examples/time/time_difference.cr index 5ba3898a4..401c01d96 100644 --- a/crystal/examples/time/time_difference.cr +++ b/crystal/examples/time/time_difference.cr @@ -1,5 +1,5 @@ time1 = Time.utc(2016, 2, 15, 10, 20, 30) time2 = Time.utc(2016, 2, 16, 10, 20, 30) -elapsed = time2 - time1 # Time::Span +elapsed = time2 - time1 # Time::Span puts elapsed.days puts elapsed.total_seconds diff --git a/crystal/examples/time/types.cr b/crystal/examples/time/types.cr index 501a5d327..5b79067f4 100644 --- a/crystal/examples/time/types.cr +++ b/crystal/examples/time/types.cr @@ -9,4 +9,3 @@ puts monotonic timespan = Time::Span.new(days: 1) puts typeof(timespan) puts timespan - diff --git a/crystal/examples/traverse_tree.cr b/crystal/examples/traverse_tree.cr index 010d5770f..685444ac2 100644 --- a/crystal/examples/traverse_tree.cr +++ b/crystal/examples/traverse_tree.cr @@ -1,9 +1,9 @@ if ARGV.size != 1 - puts "Needs path to directory" - exit 1 + puts "Needs path to directory" + exit 1 end path = ARGV[0] dr = Dir.glob("#{path}/**/*") -dr.each {|name| puts name} +dr.each { |name| puts name } diff --git a/crystal/examples/try.cr b/crystal/examples/try.cr index 44566a615..94902bde7 100644 --- a/crystal/examples/try.cr +++ b/crystal/examples/try.cr @@ -1,13 +1,13 @@ -#content = 1 -#{% if content == 1 %} -#def f +# content = 1 +# {% if content == 1 %} +# def f # puts "one" -#end -#{% else %} -#def f +# end +# {% else %} +# def f # puts "else" -#end -#{% end %} +# end +# {% end %} # joe = {} of String => Int32 | String # joe["name"] = "Joe" @@ -17,7 +17,6 @@ # # Error: no overload matches 'Hash(String, Int32 | String)#[]=' with types String, Float64 # puts typeof(joe) - # #alias Some = {} of String => Int32 | String # numbers = [] of Int32 diff --git a/crystal/examples/tuples/named_tuple_fields.cr b/crystal/examples/tuples/named_tuple_fields.cr index c53c512bc..6bbbebd2b 100644 --- a/crystal/examples/tuples/named_tuple_fields.cr +++ b/crystal/examples/tuples/named_tuple_fields.cr @@ -7,7 +7,5 @@ puts tpl["fname"] puts tpl[:lname] puts tpl["lname"] -#tpl["fname"] = "Jane" -#tpl["lname"] = "Bar" - - +# tpl["fname"] = "Jane" +# tpl["lname"] = "Bar" diff --git a/crystal/examples/use_yaml.cr b/crystal/examples/use_yaml.cr index 7cded8d3d..aed129523 100644 --- a/crystal/examples/use_yaml.cr +++ b/crystal/examples/use_yaml.cr @@ -1,7 +1,7 @@ require "yaml" data = File.open("examples/crystal.yml") do |file| - YAML.parse(file) + YAML.parse(file) end puts data puts typeof(data) # YAML::Any @@ -10,8 +10,8 @@ puts data["language"]["first_year"] puts typeof(data["language"]["first_year"].to_s.to_i) # [YAML::Any](https://crystal-lang.org/api/YAML/Any.html) puts data.as_h.keys -data.as_h.keys.each {|main_key| - data[main_key].as_h.keys.each {|sub_key| - puts data[main_key][sub_key] - } -} \ No newline at end of file +data.as_h.keys.each { |main_key| + data[main_key].as_h.keys.each { |sub_key| + puts data[main_key][sub_key] + } +} diff --git a/crystal/spec/demo_spec.cr b/crystal/spec/demo_spec.cr index 99e7cf3ab..e31f14c99 100644 --- a/crystal/spec/demo_spec.cr +++ b/crystal/spec/demo_spec.cr @@ -2,7 +2,7 @@ require "./spec_helper" describe "demo test" do it "some free text here" do - result = 23+19 # this might be calling the real application + result = 23 + 19 # this might be calling the real application result.should eq 42 end end diff --git a/crystal/spec/todo_spec.cr b/crystal/spec/todo_spec.cr index 90598e0fe..8b4972159 100644 --- a/crystal/spec/todo_spec.cr +++ b/crystal/spec/todo_spec.cr @@ -1,8 +1,7 @@ def add(x, y) - return x*y + return x*y end - describe "test cases" do it "good" do add(2, 2).should eq 4