Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jan 30 23:49
    Tamnac synchronize #13026
  • Jan 30 23:43
    Tamnac synchronize #13026
  • Jan 30 22:36
    straight-shoota milestoned #13011
  • Jan 30 22:36
    straight-shoota milestoned #13011
  • Jan 30 22:30
    oprypin edited #13026
  • Jan 30 22:03
    HertzDevil labeled #13031
  • Jan 30 22:03
    HertzDevil labeled #13031
  • Jan 30 22:03
    HertzDevil opened #13031
  • Jan 30 20:20
    straight-shoota closed #13027
  • Jan 30 20:19
    straight-shoota closed #13028
  • Jan 30 20:19
    straight-shoota closed #13025
  • Jan 30 20:19
    straight-shoota closed #13023
  • Jan 30 20:19
    straight-shoota edited #13025
  • Jan 30 20:06
    straight-shoota assigned #13030
  • Jan 30 20:06
    straight-shoota opened #13030
  • Jan 30 20:06
    straight-shoota labeled #13030
  • Jan 30 20:06
    straight-shoota labeled #13030
  • Jan 30 15:56
    straight-shoota labeled #13026
  • Jan 30 15:53
    straight-shoota converted_to_draft #13024
  • Jan 30 15:23
    Blacksmoke16 labeled #13029
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,
      #...
    })
George Dietrich
@Blacksmoke16
can you make a playground link that reproduces it?
Sean Gregory
@skinnyjames
I think so!
George Dietrich
@Blacksmoke16
i think the compiler gets the typing of the hash messed up
can re-write that part to be a case and should work fine
def handle_error(error)
  {% begin %}
    case error
      {% for k, v in klass_map %}
       when {{k}} then raise {{v}}.new(error)
      {% end %}
    end
  {% end %}
end
Sean Gregory
@skinnyjames
ah cool.
thanks!
George Dietrich
@Blacksmoke16
pp !!clazz && clazz.is_a?(Exception) # => false