<FromGitter>
<Svenskunganka> Hey fellas, I have a question about Macros. How do I embed the contents of a block as a method body? For learning purposes I am building a filetype library that matches using magic numbers (https://en.wikipedia.org/wiki/Magic_number_(programming)#Magic_numbers_in_files). I want to define a macro that allows people to add new matchers. Here's an example: ⏎ ⏎ *filetype.cr* ⏎ ⏎ ```code paste, see
<FromGitter>
<bew> it feels weird that the second test work though
<FromGitter>
<bew> Got my answer: https://carc.in/#/r/3igg it won't work if the new scope has a `FileType` module too
<FromGitter>
<Svenskunganka> Hmm that will be a problem
<FromGitter>
<Svenskunganka> Is there a way to get a reference to the `module` a macro is defined in?
<FromGitter>
<bew> Huh no don't think so
cremes has quit [Quit: cremes]
faustinoaq has joined #crystal-lang
qard has quit [Quit: qard]
jnyw has joined #crystal-lang
brycek_ has joined #crystal-lang
rohitpaulk has joined #crystal-lang
foxbot has joined #crystal-lang
brycek has quit [*.net *.split]
foxbot_ has quit [*.net *.split]
crse[m] has quit [*.net *.split]
juni0r has quit [*.net *.split]
brycek_ is now known as brycek
willamin has quit [Ping timeout: 240 seconds]
swav has quit [Ping timeout: 240 seconds]
willamin has joined #crystal-lang
swav has joined #crystal-lang
crse[m] has joined #crystal-lang
juni0r has joined #crystal-lang
rohitpaulk has quit [Read error: Connection reset by peer]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Read error: Connection reset by peer]
rohitpaulk has joined #crystal-lang
sz0 has joined #crystal-lang
hightower3 has joined #crystal-lang
hightower3 has quit [Ping timeout: 248 seconds]
hightower4 has quit [Ping timeout: 256 seconds]
DTZUZO has quit [Ping timeout: 268 seconds]
hightower4 has joined #crystal-lang
rohitpaulk has quit [Read error: Connection reset by peer]
rohitpaulk has joined #crystal-lang
DTZUZO has joined #crystal-lang
rohitpaulk has quit [Read error: Connection reset by peer]
rohitpaulk has joined #crystal-lang
Yxhuvud has joined #crystal-lang
jnyw has quit [Quit: WeeChat 2.0.1]
sz0 has quit [Quit: Connection closed for inactivity]
desdeux[m] has joined #crystal-lang
rohitpaulk has quit [Read error: Connection reset by peer]
rohitpaulk has joined #crystal-lang
hightower3 has joined #crystal-lang
hightower2 has quit [Ping timeout: 240 seconds]
rohitpaulk has quit [Ping timeout: 256 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 268 seconds]
cremes has joined #crystal-lang
coderobe has quit [Read error: Connection reset by peer]
rohitpaulk has joined #crystal-lang
<FromGitter>
<aisrael> Is there a way for a method (or overloaded methods) to behave differently whether the given block expects a parameter or not? That is, to do different things depending on block arity?
<RX14>
@aisrael no
<RX14>
you can omit block arguments to methods, so it doesn't really make sense to have that behaviour
<RX14>
i'd personally be open to changing it
p0p0pr37 has quit [Remote host closed the connection]
<FromGitter>
<aisrael> Yeah I realize in my calling method I can just `yield x` (or `.call(x)`) and have the block ignore the yielded value. Am just thinking e.g. if I wanted the behavior of `Spec.run_before_each_hooks` to pass in something if the receiving block expects something, then I can’t just override/overload it in my code. I’d have to submit a PR.
<RX14>
well you can always monkey patch
<RX14>
but yes a PR is preferred if it's possible
<FromGitter>
<aisrael> That’s the thing—I can’t monkey patch without having to rewrite `Spec.run_before_each_hooks` entirely (sure, it’s just one line but…). Submitting a PR, well, uhm, frankly am not confident about doing that yet—what if no one else thinks what I’m trying to do is useful?
<RX14>
just call previous_def?
<RX14>
previous_def { yield "foo" } ?
<RX14>
plus, what exactly are you trying to do?
<FromGitter>
<aisrael> (I’l try that, but from my experiments with blocks with 0 or 1 arity I can’t get it to work side by side with the original method). I guess the real question is: is there a way for a spec’s before/after block to know the context (`NestedContext`) of the corresponding spec?
<FromGitter>
<aisrael> (Am trying to automate generating Hi8 cassette names from the `describe` and `it should` descriptions, just like `vcr`)
<RX14>
why do you need to know that?
<RX14>
ah ok thats an extremely valid usecase
<RX14>
yeah make an issue or PR for that
<RX14>
i'm sure everyone will agree your usecase is valid
<FromGitter>
<aisrael> I actually have something that can do that now overriding `Spec::RootContext.describe`. But I figured a `before` (or rather an `around` block, if we had it) would be cleaner.
<RX14>
yeah
coderobe has joined #crystal-lang
<FromGitter>
<aisrael> Thanks! First, I’ll see about writing an `around` hook. PR that. Next, I’ll see about passing in the `NestedContext` in a second PR? Just to keep the PRs “clean"
<RX14>
im not sure around can work
<RX14>
hmm
<FromGitter>
<aisrael> oh… yeah I haven’t really given that much thought, just assumed since `before`/`after` are there that no one’s just gotten around to an `around`
<RX14>
yeah before/after are easy
<RX14>
you just call a block before and a block after
<RX14>
with around you have to pass the whole spec into the block
<RX14>
and the block can do stuff like not call the spec at all
<RX14>
it's a lot more side effects and a lot more decision
<RX14>
and a lot more power
<FromGitter>
<aisrael> I understand. That’s exactly how RSpec `around` hooks behave, too, right? OTOH RSpec `around` passes in an `example`, and the block is expected to call `example.run`. So, it’s really exposing a lot of the innards.
<FromGitter>
<aisrael> Anyway—it’s getting late (here) and really, a lot of this is still beyond my "5+ years experience with Crystal+Amber” so I’ll sleep on it and maybe the community will have better ideas :)
<vegai>
hmm, the crystal rpm package doesn't seem to be ok
<vegai>
doesn't install anything in path
<vegai>
then again, crystal & shards are in /usr/lib/crystal/bin/
<vegai>
rpm -ql crystal does show /usr/bin/crystal but I don't have that
<RX14>
lol
<RX14>
reinstall packge I guess
<vegai>
reinstalling
<vegai>
yes
<vegai>
warning: file /usr/bin/shards: remove failed: No such file or directory
<vegai>
warning: file /usr/bin/crystal: remove failed: No such file or directory
<vegai>
guess I've done something stupid again
<RX14>
probably
<RX14>
happens to me all the timwe
<vegai>
running history doesn't at least show me doing rm against them
<vegai>
perhaps the stupid thing I've done is using Linux :P
<RX14>
yeah
<RX14>
should have used plan 9
<RX14>
i should port crystal to plan 9
<RX14>
would be fun
<vegai>
more fun that porting to Windows, I'm sure
<vegai>
well ok, I'm not so sure about that
<RX14>
definitely more fun than porting to windows
<RX14>
which i've given up on until people stop bikeshedding about File::Info
<RX14>
of course Go works on plan9
<RX14>
being written by rob pike and all
<vegai>
I saw a python port at some point also
<vegai>
that was probably a bit more difficult to pull off
rohitpaulk has quit [Ping timeout: 256 seconds]
<FromGitter>
<asterite> before/after/around don't make sense for the current spec because one usually use them to setup instance vars so they are shared between tests... but spec doesn't use classes, so there's no way to access data created in a before block
<FromGitter>
<asterite> As I said it many times now, the current `spec` is probably a mistake, something like TestUnit with classes and inheritance would have better better and more flexible
<FromGitter>
<sdogruyol> @asterite aside from what you mentioned I like spec actually
instancer67 has joined #crystal-lang
<RX14>
@asterite I disagree
<RX14>
@asterite, @aisrael just provided a perfectly sane usecase for `before`/`after` which is resetting VCR state
<RX14>
around I don't think we should have
<RX14>
but I really really enjoy the current spec suite
<RX14>
I really do
pta2002 has left #crystal-lang ["WeeChat 1.9.1"]
cremes has quit [Quit: cremes]
<instancer67>
is there a way to get the input from "gets" before the enter key has been pressed?
<instancer67>
or do I have to check for every key myself to do this?
<instancer67>
wow! "STDIN.raw do |io| ; key = io.read_char ; end" works good. Why are they not just using this in the example? weird
<RX14>
because the example sucks
<instancer67>
aah.. i will do a pull request to change it
coderobe has left #crystal-lang [#crystal-lang]
alex`` has quit [Quit: WeeChat 2.0.1]
<instancer67>
RX14: this is weird. when I run the 2048.cr example and replace these 4 lines with "input = io.read_char.to_s" in read_keypress then when I press the arrow keys, it acts like i pressed CTRL+C
<RX14>
Yes
<RX14>
You're reading a single char
<RX14>
Look at the length of some of the strings
<instancer67>
aah...
<RX14>
They're 3 chars long
<RX14>
Sigh
<RX14>
Arrow keys being multiple chars breaks everything
<RX14>
Someone should just make a shard that handles this
<RX14>
The thing is you need to read from one to 3 chars
<RX14>
But no more and no less
<RX14>
And that code snippet is the only way to achieve that
<RX14>
Even that snippet makes the assumption that the read call will return one key press only
<RX14>
Even that snippet makes the assumption that the read call will return one key press only
faustinoaq has joined #crystal-lang
alex`` has joined #crystal-lang
Groogy has quit [Quit: WeeChat 2.0.1]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 260 seconds]
<instancer67>
damn this key input is laggy
<RX14>
instancer67, code?
<RX14>
it's probably because of the way you implemented it :(
sz0 has joined #crystal-lang
<instancer67>
oh its probably because i used system("clear")
faustinoaq has quit [Ping timeout: 248 seconds]
<FromGitter>
<bew> Why did you used that?
rohitpaulk has joined #crystal-lang
cremes has joined #crystal-lang
faustinoaq has joined #crystal-lang
<FromGitter>
<bew> What after you trying to do actually?
<FromGitter>
<codenoid> night
<instancer67>
i just used this for now because i wanted to test it. Im using an ascii escape sequence thingy now to clear screen
hightower2 has joined #crystal-lang
hightower4 has quit [Ping timeout: 260 seconds]
moei has joined #crystal-lang
instancer67 has quit [Ping timeout: 260 seconds]
<FromGitter>
<sdogruyol> so we removed `JSON::Type`?
<RX14>
oprypin, there's plenty discussion in the PR
<RX14>
the reason why is because it makes JSON::Any recusrsive properly
<RX14>
you will get an Array(JSON::Any) and a Hash(String, JSON::Any) from JSON::Any
<RX14>
and there's nopr ecursive aliases
<oprypin>
that's what it is, not why
<RX14>
why? because thats what people expect
<RX14>
read the PR
<RX14>
it's going to be far more informative then me trying to recall everything off the top of my head
<oprypin>
yep
cremes has quit [Quit: cremes]
cremes has joined #crystal-lang
cremes has quit [Client Quit]
rohitpaulk has quit [Remote host closed the connection]
hightower2 has quit [Ping timeout: 276 seconds]
dannyAAM has quit [Quit: znc.saru.moe : ZNC 1.6.2 - http://znc.in]
dannyAAM has joined #crystal-lang
Ven`` has joined #crystal-lang
danielpclark has joined #crystal-lang
sz0 has quit [Quit: Connection closed for inactivity]
cremes has joined #crystal-lang
Ven`` has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
return0__ has joined #crystal-lang
return0e has quit [Ping timeout: 264 seconds]
return0__ has quit [Ping timeout: 240 seconds]
return0e has joined #crystal-lang
cremes has quit [Quit: cremes]
A124 has quit [Quit: '']
A124 has joined #crystal-lang
<hightower3>
Hey folks, are there any problems with adding JSON::Any to the list of TYPES in crystal-db/src/db.cr ? I did that and it allowed me to read and write JSON to postgres database directly (field type jsonb).
<hightower3>
Jsonb appears to automatically be converted to JSON::Any in Crystal and without the above, the error shows up that JSON::Any is not in the list of TYPES so one can't read out the values from the db
alex`` has quit [Quit: WeeChat 2.0.1]
jokke has joined #crystal-lang
f1refly has joined #crystal-lang
<FromGitter>
<internethostage> Good day guys! ⏎ Newbie question alert ⏎ ⏎ My current goal is to open a jpg file, change random bytes inside, and write a new file. ⏎ To do that, my first attempt has been to try read each line of the file, and then write the output (without changes yet), however this isn't working, I suppose from changing the files content to String... ... [https://git
<imdumb>
o boi.. what is going on with my brain.. i dont understand
pta2002 has joined #crystal-lang
imdumb has quit [Quit: Page closed]
hightower2 has joined #crystal-lang
pta2002 has left #crystal-lang ["WeeChat 1.9.1"]
hightower2 has quit [Ping timeout: 256 seconds]
<FromGitter>
<asterite> RX14 for resetting VCR state we have the global Spec.before_each. Webmock uses it to reset webmocks. That's why I think that use case fits more a "global" before hook rather than ran in a particular set of specs.
<FromGitter>
<asterite> So before hooks are not really needed for this use case...
<RX14>
isn't that what was being talked about?
<FromGitter>
<asterite> Ah, sorry, I didn't read the whole conversation 😊
<RX14>
I was certain we were talking about the global Spec.before_each
<RX14>
we don't *have* anything else
<RX14>
oh
<RX14>
yes
<RX14>
we were talking about monkey-patching Spec.run_before_each_hooks to pass the Context to the Spec.before_each hook
<RX14>
I think
<RX14>
or just the spec name
<RX14>
the spec suite is weird
<RX14>
like
<RX14>
in implementation
<RX14>
externally I really like it
<RX14>
Spec's impl I think suffers from being "too OO"
<RX14>
it's so simple there should just be a single spec runner object which maintains a stack of records
<RX14>
instead of having this Context object with parents
<RX14>
but then they're also in a stack too
<RX14>
so you have to maintain each Context's parent relationship and the stack?
<RX14>
well whatever, it works
<FromGitter>
<ezrast> Is there a way to call `#class` with an implicit receiver? `self.class` fails if used in the constructor before `self` exists.
<RX14>
hmm
<RX14>
looks like you're out of luck
<RX14>
I think `self` usage should be allowed in the ctor if it's only used to call class methods