gproto23 has quit [Remote host closed the connection]
<Na_Klar>
"hello\ntest".split(" ") => ["hello", "test"] ... that's just insane. sorry. and some people wonder why developers dislike high-level languages.
erblack has joined #ruby
markong has joined #ruby
erblack is now known as erb
jpn has joined #ruby
<weaksauce>
> If pattern is a single space, str is split on whitespace, with leading and trailing whitespace and runs of contiguous whitespace characters ignored.
<weaksauce>
> As another special case, split emulates the default behavior of the command line tool awk when the PATTERN is either omitted or a string composed of a single space character (such as ' ' or "\x20", but not e.g. / /). In this case, any leading whitespace in EXPR is removed before splitting occurs, and the PATTERN is instead treated as if it were /\s+/; in particular, this means that any contiguous whitespace (not just a single space
<weaksauce>
character) is used as a separator.
<Na_Klar>
useless overkill
<weaksauce>
k
<Na_Klar>
</rant>
erb has quit [Quit: Client closed]
yCrazyEdd is now known as willow
joshcom has joined #ruby
joshcom has quit [Quit: Leaving]
joshcom has joined #ruby
<ixti>
Na_Klar: what would you expect "hello\ntest".split("\u0032") to return? o_O
<Na_Klar>
ixti, read the whole context
<ixti>
Na_Klar: I did, and still not sure what's wrong with the result
<Na_Klar>
nothing. \u0032 works as expected. it's just insane that you have to use char-codes to get the expected result, just because some parameter (!) is doing obscure magic.
<ixti>
Regardless if you pass "\u0020" or "\x20" or " " it's the same
<ox1eef_>
it's still wacky behavior, and turns the simple case into something totally unexpected.
<Na_Klar>
ixti: oh you are right, then even using a char-code does not avoid the magic
<ixti>
Well, it depends on what to consider magic :D
<Na_Klar>
imo you can't do that with a parameter. ok, you could make an own method for it. "hello\ntest".fairy_tale_split() .. why not? but do I have now to read every single api reference to be sure that some parameter will not do obscure things? that's too much of "usability".
<ixti>
Documentation is pretty clear on String#split :D
joshcom has quit [Ping timeout: 255 seconds]
<gr33n7007h>
^ this
<weaksauce>
it was inherited from perl which inherited it from awk
<weaksauce>
since ruby is very perl based it makes sense
<ox1eef_>
so, what's the alternative? how is the case handled to only split on " " ?
<Na_Klar>
then it was stupid also in perl in awk. you can't let do parameters stuff, dependant on how you write them. a " " is a straight char.
<Na_Klar>
ox1eef_: apperantly you can use .split(/ /)
<ox1eef_>
good to know
<ixti>
ox1eef_: you supposed to use regexp, yeah
<ox1eef_>
documentation or not, history or not, i don't see that as a good API. it's error prone.
<ixti>
Na_Klar: How would you know the signature of a method without reading documentation? o_O
<ixti>
guess based development? :D
<Na_Klar>
actually, I think I won't use split() anymore at all. what also is odd about ruby's split is that: "hello\n".split("\n") => ["hello"] .. in any other language I know it would be ["hello", ""]
victori has quit [Ping timeout: 240 seconds]
<Na_Klar>
which is a straigt loss of information, because I cannot disgingiush "hello\n" from "hello" anymore, after the split.
<ixti>
Na_Klar: it seems like you're actually looking for `String#lines`
<Na_Klar>
no, that has nothing do to with "\n"
victori has joined #ruby
<Na_Klar>
could be any other char
<ixti>
Oh I got what you mean.
<weaksauce>
if you read the docs you can pass in -1 to have the information you are looking for
<gr33n7007h>
Na_Klar: to get that behavior you have to pass a limit to split, which would be -1 in your case.
<weaksauce>
by default it omits null
<Na_Klar>
good lord .. more magic
<ixti>
Na_Klar: how's that magic?
desnudopenguino1 has joined #ruby
<ixti>
I really don't understand how's documented parameters handling is magic :D
<weaksauce>
it isn't
<weaksauce>
it was a design decision
desnudopenguino has quit [Ping timeout: 268 seconds]
desnudopenguino1 is now known as desnudopenguino
<Na_Klar>
... some very "apple-ish" design, as it seems to me
<ixti>
I mean, I agree that probably keyword args would be be more readable :D
vigumnov has joined #ruby
victori has quit [Read error: Connection reset by peer]
<ixti>
And it might be that method is not suitable for some specific cases...