Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Feb 05 15:55
    Blacksmoke16 closed #13047
  • Feb 05 15:53
    serge-hulne closed #13047
  • Feb 05 15:45
    Blacksmoke16 edited #13047
  • Feb 05 15:42
    serge-hulne labeled #13047
  • Feb 05 15:42
    serge-hulne opened #13047
  • Feb 05 02:16
    renovate[bot] edited #12735
  • Feb 04 23:27
    straight-shoota milestoned #12966
  • Feb 04 23:27
    straight-shoota milestoned #12966
  • Feb 04 22:45
    Blacksmoke16 synchronize #12966
  • Feb 04 12:51
    straight-shoota closed #12224
  • Feb 04 12:51
    straight-shoota closed #13034
  • Feb 04 12:15
    straight-shoota milestoned #12921
  • Feb 04 12:15
    straight-shoota milestoned #12921
  • Feb 04 10:44
    straight-shoota edited #12921
  • Feb 04 02:39
    cyangle synchronize #12921
  • Feb 04 01:08
    cyangle synchronize #12921
  • Feb 04 01:08
    cyangle synchronize #12921
  • Feb 03 22:11
    straight-shoota labeled #12794
  • Feb 03 22:11
    straight-shoota assigned #12794
  • Feb 03 22:07
    straight-shoota synchronize #12959
George Dietrich
@Blacksmoke16
sec, i have a better iea
idea
From IRC (bridge bot)
@FromIRC
<riza> yeah, I don't think inheritance is a bad choice for me here. It boxes you in a bit where you can't inherit from other sources so I don't reach for it as my first goto
<riza> that's an interesting approach...it feels a bit of a hack
George Dietrich
@Blacksmoke16
the question i always ask myself when figuring out what to do: Do you want to support both structs and classes?
if the answer is yes, you need to use a module
From IRC (bridge bot)
@FromIRC
<riza> Hm, I don't think that's material in this case. I worry that I might need to subclass some unknown other class as well, and now I have multiple inheritance problems.
George Dietrich
@Blacksmoke16
can you share more of what you're wanting to do?
From IRC (bridge bot)
@FromIRC
<riza> it's weird to me that macro ItWorksClass can be used as a type. I didn't expect that to work either
George Dietrich
@Blacksmoke16
:thinking: thats prob bug
From IRC (bridge bot)
@FromIRC
<riza> hah
<riza> the goal is to provide an interoperability layer -- a Type which can be used to declare both static and instance methods, and I want to stash the Type in a config var so the library can dereference the Type with calls like Lib.interop.do_thing and Lib.interop.new(config).do_stuff
<riza> I think for this case inheritance works fine, but I'm still surprised that there isn't a way to do this without
<riza> sorry, i totally losttrack of time and have to run
<riza> thanks for looking Blacsmoke
George Dietrich
@Blacksmoke16
could do something like that? :shrug:
o/
From IRC (bridge bot)
@FromIRC
<riza> @blacksmoke16 that's an interesting approach.
<riza> I just switched over my implementation to abstract base class and a concrete, unfortunately "Error: can't define abstract def on metaclass" comes up for abstract def self., which I've run into a few times. :⁠|
George Dietrich
@Blacksmoke16
yea, cant define abstract class methods
there's a workaround tho
From IRC (bridge bot)
@FromIRC
<riza> I guess I'll just stub it and {% raise %}
George Dietrich
@Blacksmoke16
think you can define them as abstract instance methods then extend that into the type and it'll force you to implement it
that works too
From IRC (bridge bot)
@FromIRC
<riza> I considered doing macro inherited ... extend ClassMethods ... too
<riza> if that's what you mean
<riza> maybe I like that better
<riza> that seems to produce a compiler message at an earlier phase of compilation
<riza> before code pruning or something
George Dietrich
@Blacksmoke16
:thumbsup:
George Dietrich
@Blacksmoke16
what time are nightly images pushed?
ddd
@Dan-Do
How to temporary use another CRYSTAL_PATH when running crystal build ...?
George Dietrich
@Blacksmoke16
for what reason?
CRYSTAL_PATH=/path/you/want crystal build would do it tho
ddd
@Dan-Do
Thnx, just see the new parameter of Int.to_s(base, *, precision, and want to test it :)
George Dietrich
@Blacksmoke16
:thumbsup:
ddd
@Dan-Do
why 0 is understood as true in this example? https://carc.in/#/r/c0lb
George Dietrich
@Blacksmoke16
it's a truthy value
ddd
@Dan-Do
:thumbsup:
spTorin
@spTorin
a = 1_000_000_000
puts a.humanize_bytes(format: :IEC)
puts a.humanize_bytes(format: :JEDEC)

0.93GiB
0.93GB
why IEC not puts 1GiB?
From IRC (bridge bot)
@FromIRC
<riza> I think that a GiB is actually 1_073_741_824 B
George Dietrich
@Blacksmoke16
@jgaskins what's the status of the OTLP shard you were working on?
spTorin
@spTorin
@riza but one of them must be derivation of 10^3. In your link:
one gibibyte 1 GiB = 2^30 B = 1 073 741 824 B
one gigabyte 1 GB = 10^9 B = 1 000 000 000 B
In crystal docs:
This method by default uses the IEC standard prefixes (Ki, Mi, Gi, Ti, Pi, Ei, Zi, Yi) based on powers of 1000
spTorin
@spTorin
And if you want get result based on powers of 1000, must use:
puts 1_000_000_000.humanize(base: 1000)   #=> 1.0G
Sean Gregory
@skinnyjames

Hey all
I'm trying to dynamically raise Exceptions from a macro, but when I instantiate the subclassed exception with a message, I get this error:
Error: wrong number of arguments for 'Exception#initialize' (given 1, expected 2)

Can anyone see what i'm doing incorrectly?

 macro generate_error_handling(klass_map)
      {% for klass in klass_map.values %}
        class {{ klass }} < Exception; end
      {% end %}

      private def handle_error(body)
        if body["value"]? && body["value"].as_h? && body["value"]["error"]?
          error = body["value"]
          clazz = {{ klass_map }}[error["error"]?]
          if clazz
            raise clazz.new(error["message"].as_s) 
          end
        end
      end
    generate_error_handling(
    {
      "invalid selector" => InvalidSelectorException,
      "no such element" => ElementNotFoundException,
      "invalid argument" => InvalidArgumentException,
      #...
    })