The Crystal programming language | http://crystal-lang.org | Fund Crystal's development: http://is.gd/X7PRtI | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/
sign
and fract
:sign(42.0) # 1.0
sign (-42.0) # -1.0
sign (0.0) # 0.0
fract(42.123) # 0.123
value - (value.floor)
probably?
clone
or dup
? In this case there is nothing to traverse for a deep copy, but I see some projects use clone
in this case, while others use dup
, so I'm not sure if there is a consensus.
scope.yml
having the properties roots
, paths
, etc. in a Scope
class, I'd like to avoid flow control to check the filters as scope.roots
, scope.paths
, to something like scope.filters
having their own class
Scope
with property roots
and property paths
to pull the data from the file, but what I want when creating the instance is more something like a property filters
doing when having roots
keys, Root.new(value)
, etc.
scope.filters.all? { |filter| filter.evaluate_with(path) }
ScopeFile
and using it to create the new Scope
with the correct filters
Item.new pull.read_string
and return that array
So I found another library implementing a 2D vector type, and they seem to be using a struct, and have a few methods that are clearly intended to be chained, as they return self
(in zero!
and normalize!
). Is this a bug? I would expect the wrong behavior documented here to occur for subsequent chained calls: https://crystal-lang.org/reference/syntax_and_semantics/structs.html#passing-by-value
Any particular reason why they didn't use a class here do you think? I'm confused why the code as it is written is okay, if it is.