<crystal-gh>
[crystal] faustinoaq opened pull request #6387: Fix missing comment inside code block example (master...patch-1) https://git.io/fNmpw
<crystal-gh>
[crystal] faustinoaq opened pull request #6388: Fix udp example for udp method on Socket::Addrinfo (master...patch-2) https://git.io/fNmp1
<FromGitter>
<talbergs> thanks Jarrod
khubo has quit [Ping timeout: 256 seconds]
khubo has joined #crystal-lang
moei has quit [Read error: Connection reset by peer]
moei has joined #crystal-lang
FromGitter has quit [Remote host closed the connection]
FromGitter has joined #crystal-lang
alex``` has quit [Quit: WeeChat 2.1]
akaiiro has joined #crystal-lang
DTZUZO has joined #crystal-lang
akaiiro has quit [Ping timeout: 260 seconds]
<FromGitter>
<sam0x17> does anyone know where I can find the source code for crystal's error printing code? want to replicate exactly
<FromGitter>
<sam0x17> found it myself: `ex.inspect_with_backtrace(STDERR)` does what I need
akaiiro has joined #crystal-lang
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 244 seconds]
ua has joined #crystal-lang
ua_ has quit [Ping timeout: 256 seconds]
rohitpaulk has joined #crystal-lang
akaiiro has quit [Remote host closed the connection]
bmcginty_ has quit [Ping timeout: 256 seconds]
bmcginty has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 260 seconds]
rohitpaulk has joined #crystal-lang
Philpax_ has quit [Quit: Leaving]
renzhi has joined #crystal-lang
_whitelogger has joined #crystal-lang
<FromGitter>
<soanvig> @bew It seems, that branch from PR (fixing scry to match Crystal v0.25.0) doesn't work (with Crystal v.0.25.1 at least). But @faustinoaq said, he is busy, but he will be working on that, so I will wait :)
Philpax has joined #crystal-lang
phvse has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 244 seconds]
<FromGitter>
<soanvig> I have a question. I've created getter of name `hash` in class. It has `String` type. ⏎ ⏎ Now, I get, that `.hash` has possible two types: `String` (which is my implementation) and `hash` (which is native implementation https://crystal-lang.org/api/0.25.1/Object.html#hash-instance-method)
<FromGitter>
<soanvig> I believe it's not correct behaviour, and because of that my code does not compile.
<oprypin>
soanvig, ok so maybe don't do that?
<oprypin>
it doesnt have 2 possible types, it has 1 which breaks the fundamentals of the language
<FromGitter>
<soanvig> So it is possible to overwrite native function, but typings break up then? That's huge flaw
<oprypin>
that's ruby's heritage for ya
<FromGitter>
<soanvig> So what's the point of overwriting then? To provide custom implementation of the same return type?
<oprypin>
if you have class A with one field @a and you create two instances `A.new(a=5)` and `A.new(a=5)` and by default they will not be equal and have a different hash
<oprypin>
if you want to use them in context of comparison, you must override those
<FromGitter>
<soanvig> That makes better sense, since this is 'hash' method, which is quite crucial. But what another methods?
<oprypin>
i dont understand
<FromGitter>
<soanvig> I mean, that there is method like, I don't know, Array#clear, which according to docs returns nothing. Now I overwrite it with a method, that does the same, but returns the `self` array. Now I will get errors too.
<oprypin>
maybe, maybe not
<oprypin>
depends on how bad the cascade is
<FromGitter>
<soanvig> Hm. So it seems, that thing is quite tricky, and it's best to avoid overwriting with changing typings
<oprypin>
it's best to avoid overwriting
<oprypin>
do you think a lot of good things would happen if you changed `clear` to instead double the number of items in the array while still returning nil ?
<oprypin>
but, some methods explicitly say "please override me and return a value of this type", so you can do that
<FromGitter>
<soanvig> Yes, clear was just "random" example.
<oprypin>
but you're supposed to override it in a subclass
<oprypin>
if you directly modify Array's clear method, that's bad. if you subclass and modify it - whatever floats your boat, it can work just fine
<FromGitter>
<soanvig> @oprypin in case, that I still don't change return type *
<oprypin>
it's just that the language has the assumption "hash must return int64" everywhere throughout standard library
<oprypin>
soanvig, you can do whatever you want, because existing code doesnt already rely on it, only your new code
<FromGitter>
<soanvig> Hm
<FromGitter>
<soanvig> That makes better sense nolw
rohitpaulk has joined #crystal-lang
<oprypin>
yeah sorry, i made too much focus on reopening classes, which you probably didnt even care about
<oprypin>
like `class Array(T); def clear; end; end;` - you could do this theoretically
<FromGitter>
<soanvig> To be honest, what I needed was sha256 hash, instead of UInt64 :P
<oprypin>
define `sha256` method
FromGitter has quit [Read error: Connection reset by peer]
FromGitter has joined #crystal-lang
<oprypin>
define `sha256` method
<FromGitter>
<soanvig> Thanks
<FromGitter>
<soanvig> So I've got another question. I have @a which has type of `CustomClass | Nil`, and I do: `@b = @a ? @a.method : ""`, and get that `NIl.method is undefined`. Isn't the compiler clever enough?
<FromGitter>
<soanvig> (I have such problems, because I come from other typing environment, and may not understand some things :/)
<FromGitter>
<soanvig> I've already found it and deleted old comments. I believe IRC didn't catch that
<FromGitter>
<BlobCodes> How can I make a self.load function that triggers all self.waitforload do |something| ⏎ end ⏎ ⏎ I thought about making a loop, but I wanted to know if there´s a method that´s more efficient [https://gitter.im/crystal-lang/crystal?at=5b4b2a7c6534bc5d2e5d51bd]
fbu has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 276 seconds]
fbu has quit [Quit: WeeChat 2.1]
<FromGitter>
<kingsleyh> what was IO.select and where did it go? was it removed?
FromGitter has quit [Remote host closed the connection]
FromGitter has joined #crystal-lang
<oprypin>
kingsleyh, it was removed cuz it's blocking. there's a toplevel nonblocking select i think
<FromGitter>
<jspillers> does shards log more verbose errors somewhere? I am trying to create a basic shard lib and have it be a dependency of another app... getting a `Error resolving...` message but no specific information about what might have gone wrong
<FromGitter>
<kingsleyh> oprypin - this does not stop for gets and it runs and does nothing visible
<FromGitter>
<kingsleyh> ok - now I get an error which is an improvement
<FromGitter>
<kingsleyh> Index out of bounds (IndexError)
<FromGitter>
<kingsleyh> something to do with this: print String.new buf[0, len]
<FromGitter>
<kingsleyh> although it still did not stop at the gets
<FromGitter>
<kingsleyh> I expected it would stop and let me type something at the gets
<FromGitter>
<jspillers> im creating a shard and for some reason when adding it as a dependency i have to specify the branch name or it throws `Error resolving ta4cr (0.1.0)` when doing a `shards install` - i have compared the shards.yml to other libs and it doesn't appear i am missing anything there...
<FromGitter>
<drum445> Some confusion over the Time type (as there doens't seem to be a data) When I do a .to_json on my class that contains a attr that is of type Time it is returning "2018-06-14T00:00:00Z" how can I make it only reutrn the date?
<FromGitter>
<drum445> is there just a date type?
TCZ has joined #crystal-lang
TCZ has quit [Client Quit]
<FromGitter>
<drum445> Why can't I loop through: "undefined method 'each' for JSON::Any"
<FromGitter>
<Daniel-Worrall> you need to cast it as something first
<FromGitter>
<Blacksmoke16> I feel like the to_json of that should be `"{\"latitude\":12.3,\"longitude\":34.5}"`, as the way i was thinking about it was the `@[JSON::Field(key: "lng")]` just determined the key from the JSON object to assign to that particular instance var
<FromGitter>
<bew> I don't understand what you mean @Blacksmoke16
<FromGitter>
<Blacksmoke16> see how the output is `"{\"lat\":12.3,\"lng\":34.5}"`?
<FromGitter>
<Blacksmoke16> the properties name is defined as `longitude`
<FromGitter>
<Blacksmoke16> `@[JSON::Field(key: "lng")]` should just allow you to specify a different key name (in this case `lng`) to assign to that var
<FromGitter>
<Blacksmoke16> but its actually altering the key names when doing `to_json`
<FromGitter>
<Blacksmoke16> as if i wanted to consume json `{"CamelCaseName": "value"}` and did like ⏎ ``` ⏎ @[JSON::Field(key: "CamelCaseName")]
<FromGitter>
<Blacksmoke16> to me `camel_case_name` should equal "value" and output of to_json would be `{"camel_case_name": "value"}` but oh well
<crystal-gh>
[crystal] sdogruyol closed pull request #6371: Add ECR.render for rendering without setting up an IO (master...jm/feature/ecr-render) https://git.io/fNLUc
<FromGitter>
<bew> @Blacksmoke16 then how would you make a json like the original one?
<crystal-gh>
[crystal] sdogruyol pushed 1 new commit to master: https://git.io/fNYW2
<crystal-gh>
crystal/master 24b860e Faustino Aguilar: Fix udp example for udp method on Socket::Addrinfo (#6388)
<FromGitter>
<Blacksmoke16> custom `to_json`
<FromGitter>
<Blacksmoke16> to build out the object with the original keys
<FromGitter>
<Blacksmoke16> but i guess it works in reverse, ill have to do that to get what i want from what the JSON supplies
<crystal-gh>
[crystal] sdogruyol closed pull request #6336: Improve docs of big module overloads (master...laginha87-improve-big-docs) https://git.io/fbhC8
<FromGitter>
<Blacksmoke16> `value_key` JSON::Field option would be cool, combine the parsing and transformation into one step
<travis-ci>
crystal-lang/crystal#3b3bf3f (master - Adds code samples on the big module to methods that are extending classes that are part of the standard library (#6336)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/404166174
<FromGitter>
<drum445> Hi, wondering if somebody could help me out. I have dates coming from mysql and being used in a class. ⏎ I want to return just the date via my api in JSON format.
<FromGitter>
<drum445> The problem I am having is when I do the following: https://play.crystal-lang.org/#/r/4isn ⏎ It returns the full Time object instead of just the date. Any way around this please?
<FromGitter>
<Blacksmoke16> if you dont need to full Time object you could also do like
<FromGitter>
<drum445> Thanks @Blacksmoke16, I had something similar to that but the object I have has a lot of attr so makes it a bit messy. Maybe it's the only way
<FromGitter>
<drum445> I take donations through paypal ;)
<FromGitter>
<straight-shoota> Apart from number types, there are not many conversions from string
<jokke>
drum455 try with String ;)
<jokke>
straight-shoota
<FromGitter>
<straight-shoota> but when there is, `{{ type }}.new(string)` should work
<jokke>
your right
<jokke>
*you're right
<jokke>
but it breaks for string
<jokke>
which is pretty lame
<FromGitter>
<straight-shoota> Why would you convert a String to a String??
<jokke>
well... it's just a macro
<FromGitter>
<straight-shoota> and?
<jokke>
how should i know what get's passed to it
<FromGitter>
<bew> And how would you build that type from the String? There is no generic way to build any types, unless you write it yourself.. Can you give examples?
<FromGitter>
<straight-shoota> if `string` already is a `type` there is no need to convert it
<jokke>
i'll do it like that
<jokke>
no
<jokke>
i'll do it with {% if type == String %}
<FromGitter>
<drum445> @jokke what is your use case?
<jokke>
so it won't steal any cycles at runtime
<FromGitter>
<bew> 👍
<FromGitter>
<drum445> give us a playground example
<FromGitter>
<drum445> If you are always passing in a string, why would you ever want to convert a str object?
<FromGitter>
<rishavs> @bew the object is fairly dynamic and thats the major problem. I am trying to convert an array of hashes into a tree (for my comments system). When i did it in JS, I used this small piece of code; ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ In crystal I can't proceed beyond the first line T_T [https://gitter.im/crystal-lang/crystal?at=5b4b91041c0f906b145782eb]
<FromGitter>
<bew> Can you give examples input & output, see what we can do for it?
<FromGitter>
<drum445> sounds like you might be best creating classes that have attributes of other classes if it's a nested json blob
<FromGitter>
<drum445> How is that not cleaner than a macro
<FromGitter>
<drum445> You know port is always an int
<jokke>
because let's say it's a config i use a lot
<FromGitter>
<drum445> So what's the issue
<FromGitter>
<drum445> ok, go on
<jokke>
i pass it the key as string all over the place
<jokke>
then i misspell it somewhere
<jokke>
i only know about this at runtime
<jokke>
this wont _ever_ happen with a macro like that
<FromGitter>
<drum445> I feel like you're in a mindset where you are making something more complex than it needs. I often have this too
<FromGitter>
<drum445> But if you just pass ```ENV["PORT"].to_i``` to w/e needs it
<FromGitter>
<drum445> you're sorted
<FromGitter>
<drum445> just don't spell PORT wrong, but that's the same as all Hash types
<jokke>
also i don't have to spread around multiple to_something calls just because the value i'm using isn't a string
<FromGitter>
<drum445> But you do have to call a macro
<jokke>
that's why hash types are so inferior to actual classes with attributes
<jokke>
or structs
<jokke>
what's wrong with calling a macro??
<jokke>
you do it all the time
<FromGitter>
<drum445> well not inferior, just a different approach, they have their uses
<FromGitter>
<drum445> Nothing is wrong with it mate, but there is also nothing wrong with to_i32
<FromGitter>
<drum445> and I'd argue that to_i32 is a lot easier for a new dev to understand than having to decrypt a custom macro
<FromGitter>
<drum445> Let me know what you settle on though
<jokke>
1. it's not DRY if you need it in many places in your application, 2. it's not typesafe since it's up to you to do the to_something, 3. it's very easy to misspell the key
<FromGitter>
<drum445> I wouldn't say a cast is WET
<FromGitter>
<drum445> I also would say that if you are that concerned with spelling your key wrong (for some reason) just to do a .includes?(key) before anything else
<jokke>
sure is if you do it multiple times for the exact same value
<FromGitter>
<drum445> write a helper method then
<jokke>
lol
<FromGitter>
<drum445> most useless helper I've ever seen though
<jokke>
and you said the macro was too much? :D
<FromGitter>
<drum445> exactly
<FromGitter>
<drum445> also why are you passing the ENV vars around?
<jokke>
have you ever worked with docker?
<FromGitter>
<drum445> yer
<FromGitter>
<drum445> Why do so many palces need the port
<jokke>
dude... :D
<jokke>
are you just trolling?
<FromGitter>
<drum445> Ok I'm out, I still feel you're massively over complicating things. But I have better things to be doing
<jokke>
lol
<FromGitter>
<Blacksmoke16> couldn't you just make a class tha you pass all these ENV vars to, then assign an instance of that class to like `ENV_HELPER` variable in global namespace then reference that everywhere, where you only have to do the case once in the initialize method of the class?
<FromGitter>
<drum445> indeed, but he is worried about misspelling the hash key...
<FromGitter>
<Blacksmoke16> spell check?
<FromGitter>
<drum445> tell me about it
<FromGitter>
<Blacksmoke16> i get his point but i feel like that isnt a valid enough reason to make this more complex than a class and pass all env vars to
<FromGitter>
<drum445> Agreed
<FromGitter>
<Blacksmoke16> then can cast and assign each ENV value to its own instance variable
<FromGitter>
<drum445> Just don't look at JS @jokke ;)
<FromGitter>
<straight-shoota> jokke, you probably shouldn't have multiple places reading the same value from `ENV`
<jokke>
exactly
<FromGitter>
<straight-shoota> abstracting that in a helper method, config class or whatever is better
<jokke>
which is exactly what i'm doing
<FromGitter>
<drum445> You said I was trolling when I suggested something similar
<FromGitter>
<straight-shoota> yeah, but you're likely overcomplicating it
<FromGitter>
<drum445> So if ENV is just a hash, just have ⏎ ENV["PORT_INT"] = 5000
<jokke>
it's hard for me to understand how a 4 line macro is overcomplicating things :D
<FromGitter>
<drum445> if you really have to
<FromGitter>
<drum445> compared to a 4 character cast it really is
<FromGitter>
<straight-shoota> you don't need the macro at all :D
<FromGitter>
<drum445> to_i
<FromGitter>
<straight-shoota> `setting bind_port, Int32, 3000` can just be `getter bind_port { ENV.fetch("BIND_PORT", "3000").to_i }
<FromGitter>
<rishavs> Any ideas how should I proceed ahead? :(
<jokke>
straight-shoota: i will need macros if i want to be able to check at compile time if my accessing and passing settings to methods is typesafe and correct
<FromGitter>
<drum445> Just have a helper, or a common class that holds the int
<FromGitter>
<straight-shoota> I don't follow
<jokke>
straight-shoota: of course, that's what i was going with before, until i realized that i have 15 of such lines
<FromGitter>
<straight-shoota> so be it =)
<jokke>
terrible
<FromGitter>
<straight-shoota> abstracting this in a macro adds a lot of constraints
<FromGitter>
<straight-shoota> you can't easily use custom string conversions
<FromGitter>
<Daniel-Worrall> I could also do `string[0,1]`
<FromGitter>
<bew> what is it for?
<FromGitter>
<Daniel-Worrall> I found out they have Crystal support
<FromGitter>
<Daniel-Worrall> so I've been giving it a go
alex`` has quit [Quit: WeeChat 2.1]
fluff has joined #crystal-lang
fluff has quit [Client Quit]
_whitelogger has joined #crystal-lang
FromGitter has quit [Read error: Connection reset by peer]
FromGitter has joined #crystal-lang
FromGitter has quit [Read error: Connection reset by peer]
FromGitter has joined #crystal-lang
<FromGitter>
<Daniel-Worrall> How can I group elements in an Array given that they're next to each other and satisfy a condition. ⏎ For example Array of Ints `[1, 2, 2, 3, 3, 2, 4]`, how could I group even numbers together to produce `[[1], [2, 2], [3], [3], [2, 4]]` or similar