Questions tagged [crystal-lang]

Crystal is a programming language with a Ruby inspired syntax but statically type checked and compiled to native and efficient code.

Links

Projects

660 questions
3
votes
1 answer

Calling methods dynamically (Crystal-lang)

I understand that this may be a duplicate of Any equivalent of Ruby's public_send method?. I'd like to explain what I am doing, and perhaps someone could advice. I've been porting a ruby app over the last few days to learn Crystal. I've had to cut…
rahul
  • 598
  • 1
  • 9
  • 20
3
votes
1 answer

Implementing Lazy Enumerator in Crystal

In Ruby to build a custom lazy enumerator, one can utilize Enumerator like this: enum = Enumerator.new do |e| e << value = ".a" loop { e << value = value.next } end enum.next # => ".a" enum.next # => ".b" enum.next # =>…
WPeN2Ic850EU
  • 995
  • 4
  • 8
3
votes
1 answer

Query Interface for Lucky Framework

How can I test/write queries in a terminal (Query Interface) for Lucky Framework (similar to rails console in RoR)
Jijo Bose
  • 318
  • 1
  • 7
  • 16
3
votes
1 answer

Crystal module path require issue

This is my first post so please excuse the brevity. I'm learning crystal and trying to include a file which has a shared name with another file in another path. According to the documentation I can use require "path/to/modules/" and include all…
PinkFluff
  • 78
  • 8
3
votes
1 answer

How to configure JSON.mapping for Array of Array of Strings to become a Hash?

I am trying to process the following JSON that I receive from an API. {"product":"midprice", "prices":[ ["APPLE","217.88"], ["GOOGLE","1156.05"], ["FACEBOOK","160.58"] ]} I can get a basic mapping working with: require "json" message =…
Guy C
  • 6,970
  • 5
  • 30
  • 30
3
votes
2 answers

Examine method metadata (i.e. arity, arg types, etc)

In Crystal, is it possible to view metadata on a type's method at compile time? For example, to determine the number of arguments the method accepts, what the type restrictions on the arguments are, etc. Looking through the API, the compiler's Def…
John
  • 9,249
  • 5
  • 44
  • 76
3
votes
2 answers

crystal lang : in case of a Class as a field

I'm just writting an Exception, which should stores a Class object as a field for the error message process. class BadType < Exception getter should_be : Class getter actual : Class end def feed(pet : Animal, food : Food) raise…
XQY
  • 552
  • 4
  • 17
3
votes
3 answers

How to access the results of .match as string value in Crystal lang

In many other programming languages, there is a function which takes as a parameter a regular expression and returns an array of string values. This is true of Javascript and Ruby. The .match in crystal, however, does 1) not seem to accept the…
Shadow43375
  • 514
  • 7
  • 20
3
votes
1 answer

Direct reading of an instance variable

For some reason this code will work: class Foo @foo = "foo" end Foo.new.@foo # => "foo" And I see, this feature has been used in standard library specs, but it seems to be undocumented one. So, the question is, what is the status of the feature,…
3
votes
1 answer

Hash.includes? gives weird result in crystal

I'm trying to write the Crystal equivalent of this Python code: test_hash = {} test_hash[1] = 2 print(1 in test_hash) This prints True, because 1 is one of the keys of the dict. Here's the Crystal code that I've tried: # Create new Hash test_hash =…
Nick ODell
  • 15,465
  • 3
  • 32
  • 66
3
votes
1 answer

Is it possible to get the resolved path of a broken symbolic link?

I've been unable to find a way to get the target path of a broken symbolic link in Crystal: Dir.cd "/tmp" `ln -s a b` puts File.exists?(b) # false puts File.symlink?(b) # true Is there anything in the standard library to get the address the broken…
dgo.a
  • 2,634
  • 23
  • 35
3
votes
2 answers

Does `File.info(string)/File::Info.new(string)` resolve symbolic links?

I'm using Crystal 0.25.0 and File.info(string).symlink? returns false when it should return true in the following sample: `mkdir -p /tmp/delete` Dir.cd "/tmp/delete" `rm -f b` `touch a` `ln -s a b` puts File.info("b").symlink?.inspect #…
dgo.a
  • 2,634
  • 23
  • 35
3
votes
1 answer

Parse complex YAML-structure with YAML.mapping

I have complex structure in YAML like this yaml = <<-STR 'Tunisie Telecom': regex: 'StarTrail TT[);/ ]' device: 'smartphone' model: 'StarTrail' Palm: regex: '(?:Pre|Pixi)/(\d+)\.(\d+)|Palm|Treo|Xiino' device: 'smartphone' models: -…
Sergey Fedorov
  • 3,696
  • 2
  • 17
  • 21
3
votes
2 answers

Customizing the generated SELECT in a query? [Granite ORM]

I'm trying build a JOIN query in Amber (using the Granite ORM) on a legacy database (with existing data & table structure), and wondering if it's possible to customize the SELECT FROM portion of the query to support a cross-table JOIN. Here's the…
nlh
  • 1,055
  • 1
  • 10
  • 15
3
votes
1 answer

Can't infer the type of instance variable '@id' of Document

I have the following class which is actually view model and I'm trying to initialize it based on the database model like so: class Document @id : Int64 @name : String JSON.mapping( id: Int64, name: String, ) def…
Tyler
  • 19,113
  • 19
  • 94
  • 151