From 303a70dbfe09f3fa1536165995d0e702f0b77ffe Mon Sep 17 00:00:00 2001 From: Luis Lavena Date: Tue, 15 Mar 2016 20:28:14 -0300 Subject: [PATCH] Add Type annotations and remove Symbol usage Remove Ruby's *symbols everywhere* approach to define getter/setters or properties. Crystal's parser and macros do not require symbols for these options. Also add type annotations to some elements aiming to improve quality of the documentation generated (more accurate expected types). --- src/radix/node.cr | 10 +++++----- src/radix/result.cr | 8 ++++---- src/radix/tree.cr | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/radix/node.cr b/src/radix/node.cr index 2512327..28e83cf 100644 --- a/src/radix/node.cr +++ b/src/radix/node.cr @@ -27,10 +27,10 @@ module Radix # # => [3, 2, 1] # ``` class Node - getter :key - getter? :placeholder - property! :payload - property :children + getter key : String + getter? placeholder : Bool + property! payload + property children : Array(Node) # Returns the priority of the Node based on it's *key* # @@ -54,7 +54,7 @@ module Radix # Node.new(":query").priority # # => 1 # ``` - getter :priority + getter priority : Int32 # Instantiate a Node # diff --git a/src/radix/result.cr b/src/radix/result.cr index 8064d8e..d58fc0f 100644 --- a/src/radix/result.cr +++ b/src/radix/result.cr @@ -13,8 +13,8 @@ module Radix # A Result is also used recursively by `Tree#find` when collecting extra # information like *params*. class Result - getter :params - getter! :payload + getter params + getter! payload # :nodoc: def initialize @@ -35,7 +35,7 @@ module Radix # result.found? # # => true # ``` - def found? + def found? : Bool payload? ? true : false end @@ -60,7 +60,7 @@ module Radix # result.key # # => "" # ``` - def key + def key : String return @key if @key key = String.build { |io| diff --git a/src/radix/tree.cr b/src/radix/tree.cr index 709b764..fd44954 100644 --- a/src/radix/tree.cr +++ b/src/radix/tree.cr @@ -30,7 +30,7 @@ module Radix # Returns the root `Node` element of the Tree. # # On a new tree instance, this will be a placeholder. - getter :root + getter root : Node def initialize @root = Node.new("", placeholder: true) @@ -397,7 +397,7 @@ module Radix end # :nodoc: - private def deprecation(message) + private def deprecation(message : String) STDERR.puts message STDERR.flush end