Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 13:30
    straight-shoota labeled #11360
  • 13:30
    straight-shoota labeled #11360
  • 13:30
    straight-shoota opened #11360
  • 12:51
    straight-shoota closed #11289
  • 12:51
    straight-shoota closed #11274
  • 12:50
    straight-shoota closed #11321
  • 12:50
    straight-shoota closed #11319
  • 12:50
    straight-shoota closed #11288
  • 12:49
    straight-shoota review_request_removed #11233
  • 12:48
    straight-shoota synchronize #11359
  • 12:23
    henrikac closed #11356
  • 11:54
    straight-shoota opened #11359
  • 11:54
    straight-shoota labeled #11359
  • 11:54
    straight-shoota labeled #11359
  • 11:51
    straight-shoota edited #11358
  • 11:51
    straight-shoota labeled #11358
  • 11:47
    oprypin review_requested #11233
  • 11:46
    oprypin milestoned #11353
  • 11:46
    oprypin milestoned #11350
  • 11:46
    oprypin milestoned #11351
emanzx
@emanzx
if File.file?("#{watch_log_path}")
        File.each_line("#{watch_log_path}") do |line|
        split_line = line.split(" ")
        file_path = split_line[0] + split_line[2]
        file_extension = split_line[2].split(".").last if split_line[2].split(".").size > 1
        events[file_path] = {"file_name" => split_line[2], "event" => split_line[1], "ext" => file_extension}
        end
        #cleanup the file after read
        File.open "#{watch_log_path}", "w+" { }
    end
    #dynamic event processing begin below.
    #copy the event and clean up the current.
    process_events = events.clone                                                        
    events.clear
    configs.each do |job,param|
        puts "Processing #{job}"
        process_events.each do |change, event_params|
            monitor_path = param["path"]
            if change.includes?(monitor_path)
                puts "Processing change #{change}"
            end 
        end
    end
Taupiqueur
@alexherbo2
can I use return if I yield instead of block.call?
emanzx
@emanzx
does crystal implement catch and throw like in ruby to handle nested loop?
From IRC (bridge bot)
@FromIRC
<jhass[m]> no
<jhass[m]> I never ever needed that feature in Ruby either and always found any usages of it I found strange and hard to follow
From IRC (bridge bot)
@FromIRC
<mfiano> How can I define a generic struct with all of its fields being of type T (homogeneous), where T is restricted to Float32 or Float64?
From IRC (bridge bot)
@FromIRC
<jhass[m]> We don't support restricting type variables yet. A hack is to check the type in macro land using https://carc.in/#/r/bk8d
<mfiano> :⁠( Thanks
From IRC (bridge bot)
@FromIRC
<xyhuvud> shouldn't it be possible by setting type restrictions on the constructors though?
George Dietrich
@Blacksmoke16
you could, but then you end up with a union of the two
manveru
@manveru:matrix.org
[m]
is there some trick to using @type.instance_vars in a module to get the variables of a class that it was included into?
i have this code, but both annoations and instance vars are empty:
module Test
  annotation Flag
  end

  module Configuration
    macro included
      {% puts @type %}
      {% puts @type.annotations(Flag) %}
      {% puts @type.instance_vars %}
    end
  end

  struct Config
    include Configuration

    @[Flag(name: "a", short: "a", type: String?)]
    @a : String?
  end
end
George Dietrich
@Blacksmoke16
it has to be called in the context of a method
manveru
@manveru:matrix.org
[m]
ah, i guess the problem is with the macro included...
  module Configuration
    def initialize
      {% puts @type %}
      {% puts @type.annotations(Flag) %}
      {% puts @type.instance_vars %}
    end
  end
this now gives me instance vars, but not annotations
George Dietrich
@Blacksmoke16
the problem is @type.instance_vars has to be used in the context of a method, which it is now
and annotation is empty because the macro is being expanded within the module i'd guess
manveru
@manveru:matrix.org
[m]
ah, the annotation is on the instance var
thanks :)
From IRC (bridge bot)
@FromIRC
<mfiano> I'm trying to affect how an instance of a struct prints with puts, but defining a custom to_s in the struct scope doesn't seem to do anything. What is the correct way?
George Dietrich
@Blacksmoke16
def to_s(io : IO) : Nil
then write the content to that io
From IRC (bridge bot)
@FromIRC
<mfiano> Perfect, thanks.
George Dietrich
@Blacksmoke16
there's also def inspect(io : IO) : Nil which is similar but diff
From IRC (bridge bot)
@FromIRC
* mfiano reads
<mfiano> I see.
<mfiano> Crystal is just amazing me the more I learn it. I'm pretty excited to be getting started. It's so nice to be able to just write what I mean with minimal syntax/short symbols like "to_s".
George Dietrich
@Blacksmoke16
fun fact, to_s also gets invoked if you add a var into a string. I.e. puts "Hello #{user}" is the same as puts "Hello #{user.to_s}"
From IRC (bridge bot)
@FromIRC
<mfiano> I remember reading the performance gotchas about that
From IRC (bridge bot)
@FromIRC
<mfiano> I'm struggling with multiple struct constructors. I have a struct, Foo, with @a and @b variables. I'd like to invoke it as Foo.new(1.2, 3.4), or Foo.new(1.2), in which case, @a and @b would be set to 1.2.
George Dietrich
@Blacksmoke16
is the 2nd value just the first one doupeld?
doubled
From IRC (bridge bot)
@FromIRC
<mfiano> Given one argument, both variables should be set to the same value.
George Dietrich
@Blacksmoke16
def self.new(value : Float64) : self
  new value, value
end

def initialize(@a : Float64, @b : Float64); end
should do it
From IRC (bridge bot)
@FromIRC
<mfiano> Ah so you can only have 1 initialize method?
<mfiano> I was trying to overload that multiple times :⁠/
George Dietrich
@Blacksmoke16
no, but
tl;dr i always just mke initialize represent the actual state of the instance, but then have overloaded .new to transform the arguments into something the initializer constructs
expects*
From IRC (bridge bot)
@FromIRC
<mfiano> That post was very well explained, thanks.
George Dietrich
@Blacksmoke16
From IRC (bridge bot)
@FromIRC
<mfiano> Is there a way to alias a module at the file level?
<mfiano> I don't want to remove the full qualification, but for a long/deep module that is used all over a single file, I would like to alias it to a single character or something
George Dietrich
@Blacksmoke16
technically no, but you shouldn't need to provide the FQN if its in the same namespace

or if its in a diff namespace you can do like

```