<scientes>
so that returns the pointer we want right?
<rking>
Mehhhhh
thrcka has joined #ruby-lang
<rking>
Actually, now that I look at this ruby-talk post closer, I am puzzled. The solution he does seems directly equivalent, to me. What good does the "VALUE tmp" have?
<scientes>
EXACTLY
<scientes>
is it like a ruby pointer and C pointer are differn't?
<rking>
Wait, huh?
<scientes>
well what does the VALUE macro do?
<rking>
All I mean is that as far as I know this is identical: f(g()); vs. GsReturnType tmp = g(); f(tmp_
<rking>
D'oh! messed up the last char.
<scientes>
)
<rking>
Thanks for the leg-up. =)
<scientes>
wait, what does "VALUE" do there?
<rking>
I'm working on that one. ctags didn't find it.
<scientes>
obviously if you just stuck it in a variable and then passed that variable back, assuming that there was no implicit type conversion, it would be exactly the same
<scientes>
and the compiler would actually get rid of the variable in its entirety
<rking>
OK, I'm getting a bit bleary-eyed, but it looks like we have:
<rking>
#define RUBY_ALIAS_FUNCTION_TYPE(type, prot, name, args) \ type prot {return name args;}
<rking>
OK, I have an idea... I'll try to use the pre-processor to answer this question.
<manveru>
wait, you seriously want to embed ruby?
<rking>
manveru: Why not?
<manveru>
well, good luck :)
<rking>
manveru: It's not easy?
workmad3 has joined #ruby-lang
<manveru>
embedding ruby is never easy
<rking>
That's surprising. I mean, I don't expect it to be a cakewalk, but I also don't expect it to be the kind of thing you immediately have to warn people against. =)
<manveru>
yeah, guess i'm just comparing it to things like lua :)
<rking>
Oh. Hrm.
<rking>
I'd expect it to be like, Follow Cookbookish Thing, Make Changes, Done.
<rking>
scientes: You might laugh.
<rking>
scientes: typedef unsigned long VALUE;
<manveru>
isn't that actually a pointer?
<manveru>
weird
<rking>
Perhaps it's being used that way -- this is the post-preprocessed output.
<rking>
Maybe on this system somehow it is boiling down to an 'unsigned long' by that point.
<scientes>
thats ruby.h
<scientes>
I dont get it
<scientes>
oh wait, thats silly
heftig has joined #ruby-lang
<rking>
Yes, inside ruby.h that line is only run if SIZEOF_LONG == SIZEOF_VOIDP
<scientes>
why don't they just call it THINGYMAJIG
<rking>
So a VALUE is a void*
<scientes>
or WHATCHAMACALLIT
<rking>
scientes: Because when you make jokes in code, you 100% get sick of them, because you read them again and again.
<scientes>
or there is a meaning, cause it's meaning changes due to the preprocessor
datanoise has joined #ruby-lang
<scientes>
#if defined HAVE_UINTPTR_T && 0
<scientes>
typedef uintptr_t VALUE;
<rking>
"&& 0"
<rking>
Where are you seeing that craziness?
<scientes>
at the top of ruby.h
* scientes
is getting more and more confused
<manveru>
dead code then? :)
<rking>
I'm impressed at how much changed between the two versions I'm looking at, 1.8.7 and 1.9.3
solars has joined #ruby-lang
<rking>
Entire source tree is rearranged, it seems..
<scientes>
well 1.9 is totally differn't
<scientes>
rking, that was 1.9.3
<rking>
scientes: If you look in the #elif below that it does the same thing as the 1.8.7 I pasted before: typedef unsigned long VALUE;
<scientes>
vALUE is used all over the place
<scientes>
rking, yes i greped that too
<rking>
So that's settled. VALUE is a void* that happens to be typedef'd to uint, for some reason.
<rking>
So what was the next question? Haha, I'm lost.
<scientes>
yeah but does #elif SIZEOF_LONG == SIZEOF_VOIDP
<rking>
Read it like English and don't worry about the implemtation of the symbols.
<scientes>
and is that tmp thing still neccicary?
<rking>
Perhaps the #error below will elaborate
<scientes>
ahh gotcha
<rking>
I don't know how I typed "implementation" so badly. =)
<scientes>
so is sticking the return value in a VALUE have any meaning in the example in that post?
<rking>
scientes: This post is from 2004. Perhaps at that point rb_iv_get was defined in such a way that it actually did matter.
<rking>
workmad3: Yes. It's actually a uint, but it is used as a void*.
<workmad3>
you can implicitly cast from any pointer to a void*, and from a void* to another pointer type, but you can't implicitly cast from one pointer type directly to another iirc
<scientes>
^^so abck to zero-filling
<rking>
scientes: I motion to ignore this post (for now).
<rking>
scientes: No zero-filling involved.
<rking>
scientes: If anything, the pointer arithmetic thing workmad3 mentioned, but no zero-filling.
<workmad3>
scientes: it doesn't alter the size of the pointer, just the interpretation
<rking>
Yeah. =)
<rking>
OK, let's put on the Serious Goggles and get to the bottom of this.
<rking>
We are trying to translate pre-1.9.2 " STR2CSTR(RARRAY_PTR(orig_arg)[i])" to 1.9.3.
<workmad3>
scientes: a pointer to a char is the same size as a pointer to a long (normally), but 'char* ptr; ptr + 1' is different to 'long* ptr; ptr + 1'
<workmad3>
and I need to get to work... running late :/
<rking>
workmad3: Thanks for the perspective. =)
<scientes>
wierd....
<workmad3>
scientes: C... nuff said :)
<scientes>
OHHHH i got it
<rking>
Not one thing about it is weird. =)
<rking>
Yes.
<rking>
Good.
<scientes>
its cause char* ptr +1 you add 8
zmack has joined #ruby-lang
<rking>
Exactly. 8 bits.
<scientes>
and long* ptr + 1 you add le...
<scientes>
yeah
<workmad3>
scientes: yup, that's it :)
<rking>
Now then, quoting from 1.8.7: #define STR2CSTR(x) rb_str2cstr((VALUE)(x),0)
<scientes>
so pointers are kinda like structs
<workmad3>
(although I believe normally the each pointer value addresses a byte in memory, so ptr + 1 with a char adds 1 to point to the next byte)
<rking>
And rb_str2cstr() is non-trivial. Here comes: char* rb_str2cstr(str, len) VALUE str; long *len; { StringValue(str); if (len) *len = RSTRING(str)->len; else if (RTEST(ruby_verbose) && RSTRING(str)->len != strlen(RSTRING(str)->ptr)) { rb_warn("string contains \\0 character"); } return RSTRING(str)->ptr; }
<workmad3>
but still, g2g, dave fun :)
<rking>
scientes: Pointers are not like structs, no. =)
<scientes>
well they are alot simpler :)
<rking>
That's like saying, "Phone numbers are like phones. They are simpler."
<scientes>
ok, sry
<rking>
A pointer is a name, a label, an address, a location.
<scientes>
its just that you add 1, but you are really adding something entirely differn't, cause you are counting by a differn't unit
<rking>
A struct is a thing.
Joeysomo has joined #ruby-lang
ttilley has joined #ruby-lang
gnufied has joined #ruby-lang
esad has joined #ruby-lang
<rking>
scientes: So that big old rb_str2cstr() is our new target. As you can see it does quite a bit.
<rking>
We're replacing STR2CSTR with StringValuePtr - where does rb_str2cstr come into play?
<scientes>
s/ja/en/ doesn't work..
<erikh>
wouldn't that be slower than allocating a new string anyhow?
<erikh>
I mean, the string would have to be resized and so forth
<rking>
erikh: Hrm?
<erikh>
a RSTRING overwrite is what that call does, right?
<rking>
erikh: Judging from the name alone, it's probably only returning the char* part of the Ruby String.
<erikh>
oh, I misread. my bad.
<erikh>
RSTRING(str)->ptr
<rking>
Yes, the RSTRING... lol, yep, that.
<rking>
I was typing that up exactly.
<erikh>
:)
<rking>
scientes: So we're good, right?
<scientes>
i guess so
<scientes>
i was just confused about all that tmp nonsense
<rking>
Yes.
<rking>
<rking> scientes: I motion to ignore this post (for now).
<rking>
^ Good advice. =)
<rking>
If you have trouble for some reason we can try to incorporate "VALUE tmp", but at least at that point we should have enough information to figure out why it would be necessary.
* scientes
needs to become more confident with C
<scientes>
but ruby is kinda its own C as far as i can tell..
<erikh>
ruby is it's own C as much as C is its own lisp
<erikh>
you should lay off the analogies :P
<scientes>
ok, just like the conflations
<scientes>
:P
<erikh>
they're different languages and each has things they're good at and things they're bad at
<erikh>
learning that before someone hits you with a wall of language religion will do you some good
<scientes>
no, i was talking about the C extension stuff, but whatever
<erikh>
oh. those are mostly just macros and C functions.
<erikh>
actually ruby's foreign function interface is one of the saner ones I've used.
<scientes>
ok, good to know
<erikh>
if you look at perl's XSUB or swig, you'll see some .. interesting examples
<scientes>
#if 0
<scientes>
} /* satisfy cc-mode */
<scientes>
ahh the quirks of compatibility
<erikh>
yeah. there's tons of that in there.
* scientes
wishes people used #pragma once
PhilCK has joined #ruby-lang
ankurgel has joined #ruby-lang
<andrewhl>
i have an array that looks something like this: [0, 1, 2, nil, 3, 6, nil, nil, 4, nil, 7, 35, nil]. I want to do something like this: array.index(array.max), but it chokes on the nils. How can I convert the nils to -1? Or is there another way I can extract the index of the largest number?
<andrewhl>
I tried array.map! do |x| if x.nil? x = -1 end end, but that strangely converted all the nils to -1, and all the non-nils to nil
<andrewhl>
(I'm choosing -1 but really 1 would work just as well. I just need the largest number and its index)
<ankurgel>
arr.delete(nil)
<ankurgel>
arr=[0,1,2,3,6,47,35]
<ankurgel>
arr.max => 35
charper has quit [#ruby-lang]
<ankurgel>
andrewhl: if you actually want -1 in place of nil, then: arr.collect{|x| (x.eql?(nil))?-1:x}
<andrewhl>
ankurgel: yeah, the latter
<ankurgel>
andrewhl: Choose any. Latter is doing exactly what you asked for. But, if you only wanted the maximum of an array which may/may-not contain nils, then arr.delete(nil).max is better.
<rippa>
arr.compact.max
<rippa>
is what I'd use
<rippa>
ah, you need its index
<ddfreyne>
arrrr
<ankurgel>
and rippa does it again! I knew there was a method like that, just couldn't remember.
<rippa>
will choke on negative numbers because nils are transformed into 0s
<ankurgel>
wow.
<ankurgel>
And I was doing: arr=arr.collect{|x| (x.eql?(nil))?-1:x}; p arr.max; p arr.index(arr.max)
<ankurgel>
tedious
dmathieu has joined #ruby-lang
rohit has joined #ruby-lang
gouthamvel has joined #ruby-lang
heftig has joined #ruby-lang
twelvechairs has joined #ruby-lang
ankurgel has quit [#ruby-lang]
batmanian has joined #ruby-lang
tjadc has joined #ruby-lang
scientes has joined #ruby-lang
bawer has joined #ruby-lang
workmad3 has joined #ruby-lang
yumike has joined #ruby-lang
rohit has joined #ruby-lang
tonesfrommars has joined #ruby-lang
tekin has joined #ruby-lang
gouthamvel has joined #ruby-lang
dragonkh has joined #ruby-lang
ankurgel has joined #ruby-lang
francisfish has joined #ruby-lang
morozovm has joined #ruby-lang
heftig has joined #ruby-lang
heftig has joined #ruby-lang
fvollero|gone has joined #ruby-lang
rohit has joined #ruby-lang
rking has joined #ruby-lang
hebz0rl has joined #ruby-lang
kain has joined #ruby-lang
toretore has joined #ruby-lang
Guedes has joined #ruby-lang
esad has joined #ruby-lang
ankurgel has joined #ruby-lang
gouthamvel has quit [#ruby-lang]
woollyams has joined #ruby-lang
fayimora has joined #ruby-lang
Banistergalaxy has joined #ruby-lang
ttilley has joined #ruby-lang
ankurgel has joined #ruby-lang
Indian has joined #ruby-lang
futurechimp has joined #ruby-lang
srbartlett has joined #ruby-lang
arkkkk has joined #ruby-lang
rking has joined #ruby-lang
My_Hearing has joined #ruby-lang
msisk has joined #ruby-lang
jtoy has joined #ruby-lang
Paoc_ has joined #ruby-lang
esad has joined #ruby-lang
arkkkk has quit [#ruby-lang]
mark_locklear has joined #ruby-lang
mssola has joined #ruby-lang
kain has joined #ruby-lang
solars has joined #ruby-lang
IPGlider has joined #ruby-lang
ankurgel has joined #ruby-lang
Sailias has joined #ruby-lang
m3nd3s has joined #ruby-lang
apeiros_ has joined #ruby-lang
Dreamer3 has joined #ruby-lang
spectra has joined #ruby-lang
Dreamer3 has joined #ruby-lang
slyphon has joined #ruby-lang
dejongge has joined #ruby-lang
kain_ has joined #ruby-lang
lele|w has joined #ruby-lang
sei has joined #ruby-lang
malev has joined #ruby-lang
jekhokie has joined #ruby-lang
malev has joined #ruby-lang
<jekhokie>
hello, I'm trying to create a rails view that has two select drop-downs that, when "submit" is clicked, will both store their selected values in an array to be passed to the server
kvirani has joined #ruby-lang
francisfish has joined #ruby-lang
dustacio has joined #ruby-lang
codewrangler has joined #ruby-lang
<darix>
jekhokie: #RubyOnRails
jtoy has joined #ruby-lang
regius has joined #ruby-lang
<regius>
Hi, I have a flex mock <-> ruby question. I have a block is .and_yields(value1, value2) the right way to make the block iterate over the values?
bglusman has joined #ruby-lang
<regius>
the block looks like Find_mock.find do |path| puts path end
<regius>
and i can't make it run multiple times
<regius>
Any one used flexmock .and_yields?
ankurgel has joined #ruby-lang
ThatDudeGuy_ has joined #ruby-lang
mstratman has joined #ruby-lang
kain has joined #ruby-lang
robotmay has joined #ruby-lang
morozovm has joined #ruby-lang
lsegal has joined #ruby-lang
justinxreese has joined #ruby-lang
jensn has joined #ruby-lang
morozovm has joined #ruby-lang
Sailias has joined #ruby-lang
woollyams has joined #ruby-lang
esad has joined #ruby-lang
dv310p3r has joined #ruby-lang
bryancp has joined #ruby-lang
takaokouji has joined #ruby-lang
esad has joined #ruby-lang
enebo has joined #ruby-lang
kain_ has joined #ruby-lang
dous has joined #ruby-lang
kain__ has joined #ruby-lang
regius has joined #ruby-lang
jxie has joined #ruby-lang
kain has joined #ruby-lang
rohit has joined #ruby-lang
francisfish has joined #ruby-lang
JEG2 has joined #ruby-lang
imajes has joined #ruby-lang
fayimora has joined #ruby-lang
nofxx has joined #ruby-lang
outoftime has joined #ruby-lang
mssola has joined #ruby-lang
ankurgel has joined #ruby-lang
regius has joined #ruby-lang
denysonique has joined #ruby-lang
mssola has joined #ruby-lang
Touk has joined #ruby-lang
<Touk>
puts "Hello everyone"
virunga has joined #ruby-lang
<Touk>
Come on, that was original at least..
<apeiros_>
IOError: not opened for writing
<injekt>
->e{}.(?????:??%%%)
<injekt>
oops missed a +
<injekt>
->e{}.(?????:??+%%%)
<mistym>
injekt: Ew.
<injekt>
psh
<injekt>
girls dig that stuff
<mistym>
This one doesn't ;o
<Asher>
i thought girls preferred APL
<injekt>
heh
<robgleeson|mba>
injekt: you should introduce me to these girls.
<injekt>
robgleeson|mba: come down here and I will ;D
<robgleeson|mba>
;p
<injekt>
actually I'm up your way in a couple months
<robgleeson|mba>
yeah?
<robgleeson|mba>
what for?
<injekt>
a stag do
<robgleeson|mba>
hah nice one.
<robgleeson|mba>
what part?
<injekt>
can't remember exactly, only got told last night
<robgleeson|mba>
more reason to remember :@
<injekt>
haha yeah :S
<injekt>
they weren't specific and I wasn't listening much
<injekt>
I'll find out
<robgleeson|mba>
beer ears.
<robgleeson|mba>
cool
<injekt>
;D
<injekt>
on another note, pusherapp is pretty neat
andrewhl has joined #ruby-lang
<robgleeson|mba>
using that at allur?
<apeiros_>
injekt: where's "down here"?
<injekt>
not yet, but I have a few different options to choose from and starting implementations soon
<injekt>
apeiros_: southern UK
<apeiros_>
close to london?
<injekt>
pusher looks the most polished atm
<injekt>
apeiros_: about an hours drive
<apeiros_>
I might, next year
<injekt>
cool!
<injekt>
I might be in canada then, but hey I might be here
<apeiros_>
even more likely if you have some awesome ruby or rails conf :)
<injekt>
:)
<apeiros_>
you go to canada for the full year?
<injekt>
na but my startup is canada based
<injekt>
so I plan on heading there for a while, although haven't decided yet
<apeiros_>
I see
<apeiros_>
hah, the "Oracle SQL" book by O'Reilly features a scorpion as the picture on its cover. how very fitting…
takaokou_ has joined #ruby-lang
<Asher>
their permatrip bonobo is the best
<Touk>
My employer just told me to develop a script for him using Python (quite complex, many mathematic stuff here), and I answered him that I would prefer to do it in Ruby. He's now asking me why. Since he's a very good programmer and my only answer would be "because I prefer Ruby's syntax", is there any technical advantage using Ruby to Python ? Thanks for saving my job :)
slimfit has joined #ruby-lang
headius has joined #ruby-lang
<injekt>
what's wrong with 'because I prefer ruby's syntax?'
<injekt>
why isn't that enough? you're writing it
<andrewvos>
Yeah fuck your boss
<Touk>
Isn't it a bit light ? :/
<injekt>
what?
<Touk>
He'll tell me that there are more libraries in Python etc
<Touk>
common arguments...
<injekt>
are there?
Swimming_Bird has joined #ruby-lang
<Touk>
I dunno, but he'll certainly believe it
<apeiros_>
for math stuff, there's actually quite a bit for python
<injekt>
yup there is
<injekt>
it beats ruby hands down mostly
<injekt>
but still
<mistym>
Yeah, Python is pretty well-entrenched in scientific applications.
<injekt>
those are only useful if you're using them
<Touk>
When I said complex, I meant that I have to programm the algorithms
<Touk>
their goal is complex
gsav has joined #ruby-lang
<Touk>
but it's basically array manipuation
<injekt>
the thing is, you might not have to with some of the python stuff that's available to you, to be honest I dont know why you are your boss are having that conversation if you're the only one writing this thing
<injekt>
I would tell him to fuck off and quit my job
<injekt>
but hey that's me
<Touk>
Because people have prejudices, and prejudices are strong
<injekt>
is it as strong as your reasoning to use ruby?
<Touk>
Last time, he told me to write a programm in C++ over Java because "JVM is unsecured"
<injekt>
eh
<Touk>
who in this world can use JVM's flaws ?
<injekt>
he's a troll
<Touk>
seriously ?
<injekt>
thank you for reminding me why I dont work for anyone
<Touk>
I'm working for my country's government -_-
<injekt>
(at least, dont have a boss/manager)
<Touk>
So I'll tell him I will be more productive using Ruby over Python
rippa has joined #ruby-lang
<injekt>
Touk: why dont you just write it in whatever you want to write it in and tell him it works?
Joeysomo has joined #ruby-lang
<Touk>
time is money, he'll accepet that
<Touk>
I hope
<Touk>
injekt: Military institution, you don't say what you think :D
<mistym>
Touk: Guess the other question is, will someone else have to maintain this later? If so, are there more pythonistas than rubyists in your shop?
<injekt>
^
<injekt>
only reason I would do it in python, if many other people were to maintain it and they only know python
<Touk>
mistym: Nop, it will be coded, certified, and then used as a basis of many things
<Touk>
People won't touch it anymore
<Asher>
only reason i'd do it in python is i wouldn't...
<injekt>
then he's wasting time arguing between ruby and python :)
<Touk>
I think he just doesn't know Ruby and looked a bit on Google seeing people complaining
<mistym>
Maaan, does he not know the internet?
<mistym>
People complain about *everything*
<Touk>
He's a military, he barely knows what programming is
<Touk>
he just have prejudices
<Touk>
but he's still my boss -_-
<robgleeson|mba>
you just said he is a very good programmer :p
<injekt>
then he has no place in this decision
<robgleeson|mba>
"Since he's a very good programmer …"
<Touk>
robgleeson|mba: Yeah, he's a very good programmer, he knows everything that's being said on languages
<Touk>
robgleeson|mba: But he can't code a shit
<injekt>
:S
<mistym>
I think you have a different definition of "very good programmer" than I do.
<Touk>
robgleeson|mba: To say it concretely, he has some very good knowledge into programming theory, but none in application
<injekt>
a good programmer can code a shit
<injekt>
ok im using pusher this stuff is awesome
<Touk>
injekt: I'll use ur arguments injekt, brb :D
<injekt>
what? "because fuck you, I'm using ruby!" ?
<injekt>
robgleeson|mba: does ga outsource any work?
poupoupoupoupo has joined #ruby-lang
<robgleeson|mba>
i think we have a few contracters but they're looking for permanent fixtures right now afaik.
<injekt>
word
Dreamer3 has joined #ruby-lang
<Touk>
Thank injekt, it partly worked :)
Banistergalaxy has joined #ruby-lang
kvirani has joined #ruby-lang
outoftime has joined #ruby-lang
drbrain has joined #ruby-lang
havenn has joined #ruby-lang
tommyvyo has joined #ruby-lang
datanoise has joined #ruby-lang
sandbags has joined #ruby-lang
urbanmonk has joined #ruby-lang
Radium has joined #ruby-lang
JEG2 has joined #ruby-lang
phaedrix has joined #ruby-lang
vesan has joined #ruby-lang
m3nd3s has joined #ruby-lang
datanoise has joined #ruby-lang
apeiros has joined #ruby-lang
<imperator>
ga?
* imperator
wakes up
regius has joined #ruby-lang
<any-key>
ankurgel has joined #ruby-lang
<any-key>
is there a good way to read X number of bytes from an IO object?
<any-key>
there's getbyte, but nothing that reads a certain number of bytes
rue has joined #ruby-lang
<injekt>
any-key: #read
<any-key>
hah >.<
<any-key>
thanks
<any-key>
aaaand all of a sudden things start working
<injekt>
:)
t has joined #ruby-lang
heftig has joined #ruby-lang
m3nd3s has joined #ruby-lang
phipes has joined #ruby-lang
<erikh>
imperator: hey, do you have a solaris box and don't mind testing something?
<erikh>
ISTR you testing sys/proctable on it, which is why I'm asking.
<imperator>
erikh, got a solaris vm, gimme a sec to fire it up
<imperator>
erikh, want to ask your advice about something later too
<any-key>
alternatively my previous solution could be shortened to "\xA3".bytes.first
<drbrain>
usually when you're working with bytes, unpack is the tool you want
<any-key>
it's true, I use pack several times in this with "C"
<necromancer>
is there a way to turn off the backtrace when Turn finds a skipped test? it's really annoying and useless...
<lianj>
unpack return an array though
elemarjr has joined #ruby-lang
rolfb has joined #ruby-lang
jarred has joined #ruby-lang
toretore has joined #ruby-lang
<imperator>
necromancer, config option maybe? not sure, haven't used Turn in a long time
<necromancer>
imperator: well i'm using Rails, can i do this from within config/initializers/backtrace_silencers.rb somehow? when i add turn and minitest to the list of silenced libs it doesn't seem to work
shtirlic has joined #ruby-lang
curtism has joined #ruby-lang
<imperator>
i'm afraid i don't know that one right off
<drbrain>
necromancer: minitest does not print backtraces for skipped tests by default
<imperator>
i see there's a "trace" option
<any-key>
okay, another stupid byte question: I have the string "\x04\x90" and I'm trying to turn it into an 8 bit integer
<necromancer>
drbrain: right, i think it's Turn doing it
<any-key>
unpack("C") does it for each byte rather than taking two bytes at a time
<necromancer>
imperator: i saw that but i still want backtraces for ERRORs, just not SKIPs...
<imperator>
any-key, unpack("C*")
<necromancer>
i don't even know why you'd want a backtrace for SKIP anyway. i can't think of a single reason why one would want to see the same backtrace 50 times if they skip 50 tests...
bryancp has joined #ruby-lang
<drbrain>
any-key: you can't turn 0x0490 into an 8 bit integer
<any-key>
imperator: I get [4,144], not a single integer
<bradland>
i'm giving a masters course in asking questions later :)
msisk has joined #ruby-lang
rking has joined #ruby-lang
<bradland>
burgestrand: i think i'm getting my head around it. in simplest terms: the example they provide doesn't work because Policy#requires does nothing with the second argument (options={}).
<burgestrand>
bradland: looks like it
ironcamel has joined #ruby-lang
<ironcamel>
what is the proper way to define a function with braces: def foo() { puts 'hello' }
bryancp has joined #ruby-lang
bawer has joined #ruby-lang
<manveru>
define_method(:foo){ puts 'hello' }
<ironcamel>
ah, so i guess the block syntax is the way to go
chimkan has joined #ruby-lang
<ironcamel>
def .. end
<ironcamel>
someone told me ruby supports { ... } style blocks, i guess technically they were right
<ironcamel>
what is the nicest way to define a function on a single line?
Radium has joined #ruby-lang
pw_ has joined #ruby-lang
<ironcamel>
this seems to work: def foo() puts 'hello' end
<_tca>
you should try not to
Indian has joined #ruby-lang
<ironcamel>
really?
<ironcamel>
so 3 line minimum
<drbrain>
really
<drbrain>
blocks are not the same as methods
<ironcamel>
am i using the wrong terminology?
<ironcamel>
i just mean the body of a function definition
<_tca>
ironcamel: function != method
<ironcamel>
ok ....
<burgestrand>
You’re all very… concise
<ironcamel>
i was talking about a function
<ironcamel>
yes, very precise
<burgestrand>
ironcamel: what you call functions, in ruby we call methods
srbartle_ has joined #ruby-lang
<ironcamel>
ok
<ironcamel>
the body of a method definition
<Mon_Ouie>
Ruby doesn't really have functions, it has methods and procs (anonymous functions, if you will)
<Asher>
presumably the difference is that methods are on objects whereas functions are anonymous
<ironcamel>
should always span 3 lines
<burgestrand>
ironcamel: blocks in ruby are a special kind of thing, you can write them using { … } or do … end, but they are not related to methods, or even "code blocks" from many other languages
<ironcamel>
so is there some default class all methods belong to?
<Mon_Ouie>
burgestrand: I would do more concise :p "what do you think of this syntax? def do_stuff; @foo * 3; end"
<ironcamel>
burgestrand: ruby blocks are basically closures right?
<Asher>
methods are the only thing in ruby that is not an object on its own - tho if you inquire after it you will get an object describing it
* necromancer
says function all the time when he refers to a method. so fuck you. ;)
<_tca>
yes ironcamel
<burgestrand>
ironcamel: yes
<necromancer>
if you really want to call it what it is call it a message
<necromancer>
because that's what it is
<burgestrand>
ironcamel: and as far as default class, you always have a current "self", your current context if you will
<ironcamel>
and the ruby style police say all method definitions should span 3 lines at least?
<necromancer>
#ruby-lang.send :suck_it
<Asher>
necromancer - no no a message is what invokes it ;)
<mistym>
Otherwise you go to ruby style jail.
<necromancer>
Asher: ah that's true
<burgestrand>
ironcamel: at the very topmost scope, this "self" is a special object called "main", and it’s an instance of "Object"
<ironcamel>
hmmm, main.foo() doesn't seem to work
<Asher>
ironcamel - the 3 line bit is silly just a conceptual guideline for the idea that methods should generally be small
<burgestrand>
ironcamel: you should be getting an error about a private method
wyhaines_ has joined #ruby-lang
<ironcamel>
yes
<necromancer>
ironcamel: does main = MainOrWhateverYourClassIsCalledBecauseYouDidntTellMe.new
<necromancer>
?
<burgestrand>
ironcamel: ruby’s private methods cannot be called with an explicit receiver
<ironcamel>
undefined local variable or method `main' for main:Object (NameError)
<burgestrand>
ironcamel: hehe, type "self"
<necromancer>
oh yeah :)
<burgestrand>
ironcamel: not main :)
wyhaine__ has joined #ruby-lang
<ironcamel>
private method `foo' called for main:Object (NoMethodError)
<necromancer>
what do you think this is, JAVA LAND?!?
<burgestrand>
ironcamel: there we go ;)
<necromancer>
aint no mains in ruby land
<ironcamel>
burgestrand: said there was
<burgestrand>
ironcamel: try self.send(:foo)
<burgestrand>
ironcamel: send in ruby ignores visibility, so you can force-call a private method of anything if you want to
<ironcamel>
that works
<burgestrand>
ironcamel: you can also write: public :foo
<burgestrand>
and then you can do self.foo
<ironcamel>
public :foo() ?
<burgestrand>
ironcamel: no, public :foo
<burgestrand>
ironcamel: or public "foo" might also work
<ironcamel>
in the defintion?
<burgestrand>
ironcamel: no, on a line of its own :)
<ironcamel>
or after the definition of the method
<ironcamel>
ok
<Mon_Ouie>
public is a method that expects a method name
<burgestrand>
ironcamel: public/private/protected are methods in ruby too
<burgestrand>
so you can call them like methods
<Mon_Ouie>
And it makes that method public (or those methods if there are more than one)
<mistym>
ironcamel: :foo is a symbol (a unique string), which often stands in as a method name identifier when you're calling methods that take methods as args.
<ironcamel>
yeah
<Mon_Ouie>
There's an alternative syntax: you can just do "public" on its own line, and any subsequently defined method will be public
<ironcamel>
how do i say foo is public in the declration of foo?
<burgestrand>
lots of things in very short time
<burgestrand>
:d
<mistym>
public is default, unless you've written "private" on its own line somewhere above it.
<burgestrand>
you don’t do it in the declaration, you either say "public :foo", or before you define foo you say just "public", and all methods defined after that point will be public by default
<burgestrand>
(it works the same for "private" and "protected")
<ironcamel>
oh, like c++
<burgestrand>
yeah, kind of!
<ironcamel>
default is private?
<ironcamel>
sorry if someone already answered that
<burgestrand>
ironcamel: default is actually public, except for inside the main object, topmost scope
<ironcamel>
oohhh
<ironcamel>
ok
<ironcamel>
i wonder why they did that
<burgestrand>
some things make more sense than others at first glance, does not necessarily make it bad :)
<Mon_Ouie>
Because when you define a method at top-level, it's usually some kind of helper method
<Mon_Ouie>
i.e. it ignores self, it doesn't really makes sense to call it on a specific object
<Mon_Ouie>
(private and protected aren't exactly the same as in C++, either)