Topic for #ruby is now Ruby programming language || ruby-lang.org || RUBY SUMMER OF CODE! rubysoc.org/ || Paste >3 lines of text in http://pastie.org || Para a nossa audiencia em portugues http://ruby-br.org/
Emmanuel_Chanel joined #ruby
thone joined #ruby
Cervajz joined #ruby
vereteran joined #ruby
mengu_ joined #ruby
mengu_ joined #ruby
sdavis joined #ruby
johnduhart joined #ruby
gentz joined #ruby
deadbea7 joined #ruby
fcoury joined #ruby
dubz joined #ruby
killing-joke joined #ruby
<killing-joke>
trying to start Unicorn with REE. "/usr/bin/ruby: symbol lookup error: /usr/lib64/ruby/gems/1.8/gems/kgio-2.6.0/lib/kgio_ext.so: undefined symbol: RARRAY_PTR"
<killing-joke>
i have system Ruby in /usr and Enterprise in /usr/local. i set RUBY_LIB and GEM_HOME etc, but cannot get it to find the right gems
milkshakes joined #ruby
ReinH joined #ruby
sdavis joined #ruby
minijupe joined #ruby
linduxed joined #ruby
dominikh joined #ruby
sdavis joined #ruby
savage- joined #ruby
crescendo joined #ruby
<Jarred>
How do I turn a JSON object that's been parsed into something where I can call it as object_name.variable? Is there a method that already exists for doing that or do I have to write one myself?
<ryanf>
Jarred: you can use Hash[] to turn that into a hash and then use the normal [] operator to pull values out
<ryanf>
alternately you could do like arr.assoc("created_at") I think?
ikaros joined #ruby
<ryanf>
you'd have to go a bit out of your way to get dot access like that, but I'm also not sure what the point would be compared to just making it a hash
Targen joined #ruby
<ryanf>
well, not that far out of your way. you could just use OpenStruct
yfeldblum joined #ruby
_whitelogger joined #ruby
Topic for #ruby is now Ruby programming language || ruby-lang.org || RUBY SUMMER OF CODE! rubysoc.org/ || Paste >3 lines of text in http://pastie.org || Para a nossa audiencia em portugues http://ruby-br.org/
<Jarred>
Thanks
RomD joined #ruby
<Jarred>
I'm just going to make it a Hash
welterde joined #ruby
looopy joined #ruby
knix joined #ruby
knix joined #ruby
vitoravelino joined #ruby
<apeiros_>
you could also use a method_missing "enhanced" Hash
brianherman joined #ruby
beakerman joined #ruby
eerdogan joined #ruby
justicefries joined #ruby
marcuspat joined #ruby
tayy joined #ruby
LittleBill902 joined #ruby
incluye joined #ruby
grekkos joined #ruby
<grekkos>
strange question but I'm looking to use Capistrano to deploy php web apps, has anyone done this before?
<shevy>
waaaaah
<shevy>
php!!!
xhr joined #ruby
<grekkos>
I had a feeling I'd get that kind of response
emmanuelux joined #ruby
<grekkos>
thing is I don't think PHP has anything as elegant as capistrano and rake and all that
tmart joined #ruby
brianherman joined #ruby
SaneWarning joined #ruby
tk___ joined #ruby
rpowell joined #ruby
fai|safe joined #ruby
RomD joined #ruby
rpowell joined #ruby
samxor joined #ruby
grekkos left #ruby
Manhose joined #ruby
nari joined #ruby
otakutomo joined #ruby
elevenarms joined #ruby
malkomalko joined #ruby
igotnolegs joined #ruby
travisjeffery joined #ruby
mongrelion left #ruby
rpowell joined #ruby
mikeric joined #ruby
travisjeffery joined #ruby
malkomalko joined #ruby
banisterfiend joined #ruby
krz joined #ruby
dbgster joined #ruby
duhastmich joined #ruby
<linduxed>
i need to get an explanation of the keyword "next", but googling "Ruby next" isn't really giving me any results :-P
<linduxed>
anyone who'd care to help?
<shevy>
linduxed you iterate through something. that's when you use next sometimes, to continue without caring for the specific element
<linduxed>
shevy: so like break, but not dropping out of the loop?
<shevy>
yeah
<shevy>
but I rarely need to use it, somehow it doesn't seem too useful
<linduxed>
ok
apeiros_ joined #ruby
Hachima joined #ruby
<shevy>
you can try this linduxed
<shevy>
%w( test1 test2 test3 ).enum_for(:each_with_index).map { |axis_range, index| next if axis_range == "test1"; axis_range }.map { |s| puts s }
<shevy>
in IRB
<shevy>
it will omit test1
Mahoek joined #ruby
Clooth joined #ruby
<samuelkadolph>
enum_for? Why?
<shevy>
does it matter
<samuelkadolph>
It looks fugly
stephenjudkins joined #ruby
<shevy>
%w( test1 test2 test3 ).map { |axis_range, index| next if axis_range == "test1"; axis_range }.map { |s| puts s }
<shevy>
are you happier now :D
mattp_ joined #ruby
xol joined #ruby
<samuelkadolph>
You forgot each_with_index
<shevy>
I am going to write the perfect oneliner
<samuelkadolph>
Then you wouldn't use next but select :P
<shevy>
ah I don't really use next myself
<shevy>
that was all part of me trying to help linduxed :(
<samuelkadolph>
Your first example was better
<shevy>
but you didn't like it
<samuelkadolph>
I mean the while gets one
<shevy>
ah that one
<shevy>
hmm I don't like that one either though
<shevy>
somehow I don't use while myself
stercor joined #ruby
<stercor>
How do I clear "undefined method 'require_gem'" error?
LittleBill902 joined #ruby
goodieboy joined #ruby
<goodieboy>
I just pushed a gem to rubygems.org but need to push a tiny enhancement (not a fix or additional feature). If my gem is at 1.2.1, what should the next version be?
iamjarvo joined #ruby
<goodieboy>
... basically, I'm making the dependencies less strict
<shevy>
goodieboy 1.2.2 :D
<shevy>
unless you care much about the minor version
<goodieboy>
shevy: Nah, just curious about what others are doing
<goodieboy>
1.2.2 ... good enough for me :)
<shevy>
well 1.3.0 wouldn't be worth it since it is just a bug fix ... what could be done is kill the 1.2.1 and release the new 1.2.1 too ... though 1.2.2 would probably make more sense
Draco_ joined #ruby
<goodieboy>
shevy: yeah makes sense, I think I'll go with 1.2.2
<jimmy__>
to re-release 1.2.1 kinda defeats the purpose of versioning
austinbv joined #ruby
thone_ joined #ruby
Banistergalaxy joined #ruby
Draco_ joined #ruby
flip_digits joined #ruby
mikeric joined #ruby
rsampaio joined #ruby
banister_ joined #ruby
LittleBill902 joined #ruby
thone joined #ruby
tayy joined #ruby
marcuspat joined #ruby
ziggles joined #ruby
<ziggles>
Could someone please confirm if this is a bug in ruby... Or that I dont understand a simple regex? http://pastie.org/2922243
banisterfiend joined #ruby
<TheMoonMaster>
ziggles: Declare $foo (eg: $foo = "derp") before you run that and watch what happens
<ziggles>
TheMoonMaster: I see that it's interpolating it
Behi joined #ruby
<TheMoonMaster>
Yup.
<TheMoonMaster>
I've never seen it used like that, so I was surprised myself.
<ziggles>
TheMoonMaster: hmm... if user input was given to a ruby script that contained something like: #$herpin would that still be ok?
<ziggles>
TheMoonMaster: yeah ive never seen it either and bugging the people in #rails i see that it's a commonly used/known shorthand
<ziggles>
well common to those who know lol
nerdy_ joined #ruby
<samuelkadolph>
String interpolation doesn't work like that
skrewler joined #ruby
<TheMoonMaster>
samuelkadolph: Why is it working then? Just a weird bug?
<samuelkadolph>
You can omit the {} for instance, class and global variables
<ziggles>
please send all profits to TheMoonMaster and samuelkadolph
<draginx1>
lol
xol joined #ruby
marcuspat joined #ruby
macmartine joined #ruby
minijupe joined #ruby
dotnull joined #ruby
Pip joined #ruby
Pip joined #ruby
LittleBill902 joined #ruby
Targen joined #ruby
goodieboy joined #ruby
EddieS joined #ruby
cbuxton1 joined #ruby
LittleBill902 joined #ruby
looopy joined #ruby
stercor joined #ruby
<stercor>
RoR seems to require sqlite3. How can I eliminate this requirement?
Manhose joined #ruby
incluye joined #ruby
LittleBill902 joined #ruby
looopy joined #ruby
justinmcp joined #ruby
xol joined #ruby
m_W joined #ruby
akem joined #ruby
akem joined #ruby
pac1_ joined #ruby
wmoxam joined #ruby
rpowell joined #ruby
kennethreitz joined #ruby
x0F__ joined #ruby
espeed joined #ruby
indigo_ joined #ruby
dasfugufish joined #ruby
dotnull joined #ruby
incluye joined #ruby
<deryl>
it doesn't. (also see the #rubyonrails channel instead)
Norrin joined #ruby
<deryl>
its set in Gemfile to default to sqlite. modify your Gemfile and bundle install. Or if this is an older Rails app, modify your config/database.yml and add the gem to the environment for whatever db you're going to use
<deryl>
google has tons of examples
stephenjudkins joined #ruby
justinmc_ joined #ruby
<shevy>
deryl he is long gone!
draginx1 left #ruby
savage- joined #ruby
<deryl>
damn, i keep getting nailed with the join part quit blocks. :) got tired of all that noise. causes me to occasionally respond to someone i never saw leave
Banistergalaxy joined #ruby
tmart joined #ruby
<deryl>
there, should fix that crap.
CannedCorn joined #ruby
justinmcp joined #ruby
radic_ joined #ruby
MekkisFreenode joined #ruby
flynn84 joined #ruby
justinmcp joined #ruby
kuadrosx joined #ruby
ryanf joined #ruby
cbuxton joined #ruby
flynn84 left #ruby
wmoxam joined #ruby
tomku|two joined #ruby
otakutomo joined #ruby
justinmcp joined #ruby
fai|safe left #ruby
xol joined #ruby
emmanuelux joined #ruby
randym joined #ruby
emptyflask joined #ruby
jhonce joined #ruby
_catch joined #ruby
Draco_ joined #ruby
Banistergalaxy joined #ruby
luckyruby joined #ruby
AndChat- joined #ruby
banisterfiend joined #ruby
austinbv joined #ruby
Banistergalaxy joined #ruby
banisterfiend joined #ruby
marcuspat joined #ruby
dotnull joined #ruby
ksinkar joined #ruby
macmartine joined #ruby
friskd joined #ruby
pen joined #ruby
michael_mbp_ joined #ruby
dotnull joined #ruby
looopy joined #ruby
rickmasta joined #ruby
rickmasta joined #ruby
jmeeuwen joined #ruby
emocakes joined #ruby
rippa joined #ruby
radmacd joined #ruby
Banistergalaxy joined #ruby
Azure joined #ruby
Azure joined #ruby
akem joined #ruby
akem joined #ruby
Azure joined #ruby
Kamoi joined #ruby
amacgregor_ joined #ruby
Hachima joined #ruby
S1kx joined #ruby
S1kx joined #ruby
maukoquiroga joined #ruby
<maukoquiroga>
hi !
banisterfiend joined #ruby
tomb joined #ruby
gh joined #ruby
LittleBill902 joined #ruby
banisterfiend joined #ruby
tomb joined #ruby
macmartine joined #ruby
dnyy joined #ruby
Banistergalaxy joined #ruby
eldariof joined #ruby
michael_mbp joined #ruby
LittleBill902 joined #ruby
ksinkar joined #ruby
skim1776 joined #ruby
xpot joined #ruby
jarjar_prime joined #ruby
friskd joined #ruby
Indian joined #ruby
LittleBill902 joined #ruby
Banistergalaxy joined #ruby
banisterfiend joined #ruby
LittleBill902 joined #ruby
otakutomo joined #ruby
tolland joined #ruby
<tolland>
hi
sorin joined #ruby
<tolland>
Are there any packagers of ruby for CentOS 5? (I have installed a source ruby 1.8.7, but centos is insisting on the ruby 1.8.5 packages from the repo)
<tolland>
i mean ruby 1.8.7 or above
<shevy>
compile from source!
<shevy>
wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p334.tar.bz2; tar -vjxf ru*33*bz2; chdir into and, configure with --prefix=/usr, make and make install!
<ryanf>
haha
<ryanf>
I read that as like
<ryanf>
ru*b33*z
<ryanf>
thought you were doing some kind of l337 thing
IrishGringo joined #ruby
zenergi joined #ruby
<shevy>
nah, just too lazy to type out the full :)
<shevy>
ruby 1.8.5 is really very old
thecreators joined #ruby
<skim1776>
are RSpec and Cucumber always used together?
yxhuvud joined #ruby
enikar joined #ruby
<tolland>
shevy: i can install from the ruby source but, the existing tools wont use the newly created binary with some jiggery in the symlinks
<shevy>
hmm symlinks?
thebastl joined #ruby
<tolland>
or ill have to install all the apps that need ruby from source as well
<tolland>
are there like 1.9 or 2 rpms for centos that I am missing somehow?
LouisJB joined #ruby
<ryanf>
skim1776: not necessarily, lots of people use rspec without cucumber
<ryanf>
there are probably not many people using cucumber without rspec though
<skim1776>
so cucumber goes with rspec, but rspec is independent from cucumber
Morkel joined #ruby
<ryanf>
something like that
thebastl joined #ruby
sahli_ joined #ruby
justinmcp joined #ruby
stephenjudkins joined #ruby
<skim1776>
can we say that Cucumber is not necessary for the testing - it's kinda luxury?
LouisJB_ joined #ruby
Seisatsu joined #ruby
eerdogan joined #ruby
stephenjudkins joined #ruby
justinmcp joined #ruby
stephenjudkins joined #ruby
ofcourse joined #ruby
<ofcourse>
hi, I've just installed ruby on Win7 using rubyinstaller and when I try to print from the command line I get this error: "Unable to initialize device PRN"
<indigo_>
Turns out the Windows gems are compiled against 1.9.2 instead of 1.9.3
<indigo_>
But whatever, it's a learning experience :P
<skim1776>
can we test only classes using rspec?
<shevy>
tolland when your ruby installation works, you can install rubygems, then install everything via gems
<shevy>
only very few gems need any form of compilation... hpricot comes to mind I think
<shevy>
tolland that's always the question, every distribution has its own packages, packages formats, and expects you to know where to look for these, or how to install them. :) I myself was too lazy for that. These days I either install something myseful, via setup.rb rake or gems
stepnem joined #ruby
stephenjudkins joined #ruby
LittleBill902 joined #ruby
<banisterfiend>
rippa: do u ever stay up all night teasing and abusing your dog for being a different species
<srji>
puts outputs an integer, p outputs a string
<srji>
i don't understand the difference
<shevy>
p calls #inspect on your object, puts calls #to_s on your object
Mahoru`Tsunemi left #ruby
<srji>
when puts calls #to_s, does it have to output a string?
<srji>
s/does/should
ramkash left #ruby
bosphorus joined #ruby
<shevy>
srji not sure... redefine it and see?
DaZ joined #ruby
Htbaa left #ruby
<srji>
i see
<srji>
it's the same
tolland left #ruby
<apeiros_>
seems puts falls back to Object#inspect if to_s does not return a string. and by Object#inspect, I mean it forgoes the object's own inspect and uses the core implementation directly.
justinmcp joined #ruby
<yxhuvud>
interesting.
<apeiros_>
consider: ruby-1.9.3-p0:055:0>> x = Object.new; def x.to_s; 1; end; def x.inspect; "hello"; end; puts x
<apeiros_>
#<Object:0x007fdd9104acb0>
<apeiros_>
that's ruby 1.9.3, as you can see. I don't know how it is in older rubies. I thought 1.8 raised.
<yxhuvud>
shouldn't matter too much anyhow - not returning a string from to_s should be stomped upon
<apeiros_>
I'd raise
<yxhuvud>
agreed
<apeiros_>
IMO it's clearly a bug if somebody tries to puts a non stringifiable object.
fermo joined #ruby
eldariof joined #ruby
<apeiros_>
also consider: ruby-1.9.3-p0:056:0>> String(x)
<apeiros_>
TypeError: can't convert Object to String (Object#to_s gives Fixnum)
<apeiros_>
so Kernel#String() IMO does it right
<yxhuvud>
I suppose it is consistent with to_i and Integer behaviour though
<apeiros_>
now we could make fun of it and see what it does when the object it returns reports a class that does not return a string on to_s :D
tvo joined #ruby
tvo joined #ruby
<apeiros_>
aw, mean, they (quite expectedly actually) don't go via the object's methods to determine the class :(
<shevy>
hehe
<Mon_Ouie>
Bad things would happen if they relied on object.class; they would try to access fields that are only available on strings on something that isn't really a string
<apeiros_>
of course
bosphorus joined #ruby
justinmcp joined #ruby
bluOxigen joined #ruby
cyri_ joined #ruby
Telling joined #ruby
EddieBluh joined #ruby
justinmcp joined #ruby
pkkm joined #ruby
duey joined #ruby
ikaros joined #ruby
gener1c joined #ruby
<gener1c>
if i load 2 different files in which i have 2 different constant variable assingments to the same constant variable name
<gener1c>
would that be an issue since im loading them to the same namespace?
<gener1c>
response: no such file to load "/home/user/loading_file.rb"
codespectator joined #ruby
<apeiros_>
gener1c: you probably want require instead of load (that won't solve your issue, though)
<apeiros_>
gener1c: both load & require use $LOAD_PATH to find files you try to require.
<gener1c>
so i need to make a bash file that will assign something new to $LOAD_PATH?
<apeiros_>
so you need to make sure in your env or executable (and *only* in your executable, not in your library/loaded files/etc. - that'd be bad style) that your $LOAD_PATH is correctly set up
jorum joined #ruby
<apeiros_>
one way is to wrap your stuff into a gem and install the gem. rubygems will then deal with the load path for you.
<apeiros_>
another way is to use the -I (capital i) option with ruby: ruby -I/path/to/your/lib /path/to/executable.rb
<apeiros_>
paths can of course all also be relative to your working directory, e.g. ruby -Ilib bin/exe.rb
robotmay joined #ruby
<apeiros_>
and a third way (IMO the worst way) is that your executable knows where the lib directory is located relatively to itself and adds it to $LOAD_PATH.
<gener1c>
wont use it then
<gener1c>
i tried changing load to require
<gener1c>
it doesnt recognize the file
<gener1c>
do i need to use full path?
<gener1c>
require './file.rb'
<gener1c>
got it
<apeiros_>
code for a typical PROJECT/bin/exe.rb, PROJECT/lib/foo/bar.rb where exe.rb tries to `require 'foo/bar'`: http://pastie.org/2923548
robyurkowski joined #ruby
<apeiros_>
you don't need the './' and '.rb'. by convention you just do: require 'file'
<gener1c>
so all my classes should be in a lib dir
<gener1c>
and just the main should be in bin
<apeiros_>
another convention btw. is to have a file per class & per module. that is, Foo goes into foo.rb, and Foo::BarBaz::Quuz goes into foo/bar/quuz.rb
<apeiros_>
if the main is an executable, then yes, it belongs into bin
Draco_ joined #ruby
<gener1c>
i do a class per file
<apeiros_>
whoops, that should have been foo/barbaz/quuz.rb
<apeiros_>
aw, fuck, I was still logged in under the company account when I gisted that =(
<tinhead>
Ruby threads don't seem to get killed when the variable they are assigned to goes out of scope. How does one go about achieving this? Via ObjectSpace.define_finalizer?
<apeiros_>
tinhead: you have to stop the thread
<apeiros_>
and yes, threads keep running, regardless of whether they're still referenced anywhere.
<gener1c>
so the thing you posted to pastie is the proper way to do it?
<tinhead>
apeiros_: Simply put, my problem with using define_finalizer is that the thread get's created in the object space. So no amount of abstraction seems to enable me to kill the threads when they are GCed.
<apeiros_>
what do you mean, "gets created in the object space"?
<apeiros_>
gener1c: what I pasted is way 3 done properly
<apeiros_>
way 1 & 2 are to be prefered IMO
<tinhead>
apeiros_: I do Thread.new in initialize.
<apeiros_>
and what stops you from storing it somewhere?
<apeiros_>
btw., finalizers aren't guaranteed to be run, neither are there any constraints as to when they'll be run, if they're run
<tinhead>
I did try puting it in an array which is a class variable. The finalizers don't run.
<tinhead>
apeiros_: I manage how often GC runs by calling GC.start at the right spots.
<tinhead>
apeiros_: Hm, so there is no guarantee that finalizers will be called even if I do GC.start?
<apeiros_>
tinhead: my knowledge on that is limited, but that's how I understood it, yes.
<apeiros_>
also if you fail to account for even a single reference, the finalizer is guaranteed to not run
<apeiros_>
finalizers are IMO the wrong way to perform an action that must be performed
<apeiros_>
and even more wrong if timing matters too
<killing-joke>
my test app won't launch, saying i did not do "bundle install". why is this step necessary?
<apeiros_>
killing-joke: because your app uses bundler.
<tinhead>
apeiros_: hmm, timing doesn't resources do, a load average of 40 on 8 cores does
<tinhead>
apeiros_: thanks for time, I'll let the room know if I am able to crack this one
Mchl joined #ruby
Tuxist joined #ruby
<killing-joke>
apeiros_, thanks. i guess i see this in the gemlist. (running ... ) boy, there were a bunch of unmet dependencies.
Locke23rus joined #ruby
Ch4rAzZz joined #ruby
dbgster joined #ruby
trivol joined #ruby
LittleBill902 joined #ruby
RomD joined #ruby
EddieBluh joined #ruby
Silker joined #ruby
Sliker joined #ruby
codespectator joined #ruby
kalusn joined #ruby
g0bl1n joined #ruby
justinmcp joined #ruby
Jake232 joined #ruby
mengu joined #ruby
Mch1 joined #ruby
smgt joined #ruby
banister`movie joined #ruby
akem joined #ruby
Backsorry joined #ruby
akem joined #ruby
_walle_ joined #ruby
<_walle_>
Hello, trying to find the escape character in slim so I can output the character # in my template, but can't find it anywhere. Anyone know how to do this? Please tell me if this is the wrong place to ask :)
<apeiros_>
_walle_: I don't know slim, but \ is probably the most often used escape character
<pen>
hey
<pen>
how do I have a each block in a array select block?
<pen>
ruby complains about block within block
kirun joined #ruby
<_walle_>
apeiros_, thx, not in slim apparently :) I went around the problem instead
<apeiros_>
(preferably on the bottom to keep line numbers intact)
flip_digits joined #ruby
<pen>
apeiros_: added
<pen>
apeiros_: the weird thing is that, ok let me show you another method I have
<apeiros_>
pen: seems like list1 == true, not an array
<apeiros_>
nothing to do with the nesting
<pen>
apeiros_: I just added another method in the paste, that def segment output is used as an input to this code
<pen>
apeiros_: so list1
Algorith joined #ruby
<pen>
apeiros_: and i'm sure that def segment returns an array
<pen>
apeiros_: that's where it gets weird
<apeiros_>
pen: you can be sure all you want, ruby tells you it's not :)
<apeiros_>
so all you need to do now is when things start to go wrong
<apeiros_>
you can make sure my assumption is correct by inspecting list1 before that loop
<apeiros_>
e.g. `p :list1 => list1`
<pen>
apeiros_: just do list1.inspect?
tayy joined #ruby
<apeiros_>
should print: {:list1 => true}
<apeiros_>
while you expect {:list1 => […something in here…]}
<pen>
apeiros_: you are wrong
<pen>
apeiros_: it prints out the list
<pen>
apeiros_: ruby is wrong
<apeiros_>
…sure
<Algorith>
Has anyone before encountered a similar problem? Whenever I run a program containing a 'sudo' command Aptana completely crashes :s, pretty sure it's sudo related, when I run Aptana as root there are no problems at all.
<pen>
apeiros_: yea, that's weird. because I inspect the list and it shows up in the structure I wanted
<apeiros_>
pen: is the code small enough to paste it completly? with sample input that'll trigger the exception?
<apeiros_>
Algorith: #ruby channel here, I think you wanted another channel…
<pen>
apeiros_: it's not small and it has to do with other db structure then I have also paste that if you want to understand the list structure.
<pen>
apeiros_: but let me tell you one thing, list1 is a list, it is not a true value
<apeiros_>
pen: can you reduce it to a reproducable case?
<apeiros_>
pen: your exception tells you otherwise
shevy joined #ruby
<pen>
apeiros_: let me try
<apeiros_>
"5:in `block in filter': undefined method `each' for true:TrueClass (NoMethodError) " this *very clearly* states that you're trying to call `each` on true
<apeiros_>
try it in irb if you want: true.each {}
<apeiros_>
$ ruby -e 'true.each {}'
<apeiros_>
-e:1:in `<main>': undefined method `each' for true:TrueClass (NoMethodError)
<apeiros_>
there. precise error you get.
<apeiros_>
are you sure the error happens in the place you say it does?
<apeiros_>
(line number in the backtrace helps with that…)
<Mon_Ouie>
No, it returns true if it finds one element in the array for which the condition is true
<apeiros_>
pen: ri Enumerable#any?
<pen>
oh
<apeiros_>
I strongly suggest reading through all of Enumerable's methods
<pen>
ok
<apeiros_>
they're very useful
<apeiros_>
also lots of things in ruby are Enumerable
jbw joined #ruby
<linduxed>
are the arguments to a function like "def foobar(a, b, c)" stored in some array?
<apeiros_>
linduxed: no
<linduxed>
apeiros_: ok...
<apeiros_>
also, it's methods, not functions
<linduxed>
sorry
<linduxed>
jargon slipping now
<apeiros_>
you can define the method as: def foobar(*args)
<apeiros_>
then all arguments will be stored in args as an array.
<linduxed>
oh i see, that sounds pretty handy
<gener1c>
a method is a function/procedure that is attached to an object
<linduxed>
although in this case it won't be possible
<pen>
spacebug: that's cool
<pen>
apeiros_: cool
<apeiros_>
it is. it's also what makes variable number of arguments possible
<gener1c>
like in c
<gener1c>
:P
<apeiros_>
C has a splat operator? :)
<gener1c>
hehe nope
<linduxed>
hmmm
<gener1c>
but i think a defined amount of arguments is important in most cases
<gener1c>
an array could be used instead for example
<apeiros_>
there are variadic functions in C
<apeiros_>
see e.g. printf
<gener1c>
yeah i know
<gener1c>
i forgot how to make those but i have the K&R here
<gener1c>
so i can find out
<gener1c>
or maybe i can just google it
<linduxed>
i've got a problem here, i've got a function that takes three integer arguments. i need to check how many of those are equal
<linduxed>
so if a = b != c then it should return a certain value
<linduxed>
either there are two, three or no equal integers
<Mon_Ouie>
To be able to call a variadic function with an array of arguments, you need an alternative function that doesn't really expect variadic arguments
<Mon_Ouie>
e.g. vprintf for printf
<linduxed>
my first thought was to just go making a set of if statements, but that feels so sloppy
<linduxed>
is there a better way?
<apeiros_>
linduxed: 3 ifs should be the fastest way to do it
<gener1c>
:P
<apeiros_>
there's others, but I think with just 3 values it's the easiest too.
<apeiros_>
actually 4 if's
<apeiros_>
meh, 3 ifs. or exists, after all…
LittleBill902 joined #ruby
<linduxed>
apeiros_: ok then it was as i thought... i'm getting detrimentally hesitant to type code when i think it would be ugly
<linduxed>
s/think/suspect/
<apeiros_>
don't overthink stuff
<apeiros_>
if it takes you 2minutes to write an ugly solution and 30 to think of a nice one - write the ugly one and use the 28 minutes saved to write tests.
<Mon_Ouie>
How do you know it takes 30 minutes to find the good one, and not 5, though?
<gener1c>
blocks are amazing
<apeiros_>
how do you know you found a good one at all?
<gener1c>
are there different ways to use them or are they always used when iterating ?
<apeiros_>
one nice thing about the human mind is a thing called "incubation". you don't need to actively think about a problem. your brain will still try to solve it.
<gener1c>
ah wait i can use them like callback functions
<apeiros_>
so if you have a solution, go with it. test it. and then if your brain suddenly pops a nice solution that is different, you can implement it without fear of regressions
<Mon_Ouie>
def foo; yield 3, 4; end # this calls the block with 3 and 4
<gener1c>
now i need to find a callback function usage article
<apeiros_>
gener1c: you can store a block using &varname syntax
<apeiros_>
def foo(&block); @callback = block; end
<gener1c>
def function(var1,var2,&block)
<gener1c>
yeah
<gener1c>
wait what
<apeiros_>
when you call foo with a block, that block will be stored in @callback and can be invoked using @callback.call
<apeiros_>
at any time.
<gener1c>
humz
<gener1c>
implicit lambda?
<apeiros_>
o0
<gener1c>
is that an implicit lambda invocation?
<gener1c>
you made a proc from that block
<apeiros_>
never heard that term…
<gener1c>
without using the lambda word explicitly
<gener1c>
i thought i was supposed to use yeald
<gener1c>
yield
<apeiros_>
well, yes, ruby can (and does) convert from block to proc and vice versa
<apeiros_>
yield will always invoke the block passed to the *current* method
<apeiros_>
but if you save a block and use it in a different method, it's no longer the block passed to the current method…
<gener1c>
ohhhhhhhhhhh
<gener1c>
but wouldnt that hurt the readablility of the code?
<apeiros_>
no
<apeiros_>
consider things like: after 5.minutes do puts "5 minutes are over!" end
<apeiros_>
you'll save that block to invoke it after 5 minutes
<apeiros_>
or:
<apeiros_>
button.on_click do puts "you clicked the button" end
<apeiros_>
you'll save that block in order to invoke it whenever you detect a click
* shevy
clicks on apeiros_
<gener1c>
lol
* apeiros_
feels clicked
Johnnus_ joined #ruby
BAR_MEN joined #ruby
<apeiros_>
or: class Foo; extend Validations; validate :attribute do |val| … end; end # <-- you'll store the block to invoke it whenever you want to validate an instance of Foo
<apeiros_>
the possiblities are huge.
<apeiros_>
and yes, blocks are awesome.
bosphorus_ joined #ruby
<shevy>
:)
<apeiros_>
procs likewise, but the syntax sugar that is blocks makes it super nice to use.
<shevy>
you wanted to be able to pass multiple blocks to the same method once, or?
<apeiros_>
shevy: wanted? I still want.
<shevy>
ah ok
<apeiros_>
they tried but fell short IMO with ->{}
<gener1c>
pass em as a proc array?
<shevy>
hmm don't like the -> notation too much myself
<shevy>
skyrocket operator!
<shevy>
a proc array?
<rippa>
I wonder why -> doesn't use |x, y| format
goodieboy joined #ruby
<apeiros_>
gener1c: yes, you simply pass procs, whether as individual arguments, as array, or as hash doesn't matter
<apeiros_>
it's about the syntax
<apeiros_>
rippa: probably amibguity issues in the syntax
m_W joined #ruby
<gener1c>
whats wrong with [&blcok1,&blcok2]
<apeiros_>
gener1c: that's not how you invoke the method
<gener1c>
no im talking about an alternative to ->{}
<gener1c>
you cant pass an anonymouse array anyways
<apeiros_>
o0
<apeiros_>
of course you can
<gener1c>
you can!?
<gener1c>
nono i mean
<apeiros_>
foo([1,2,3]) # <- sure
<gener1c>
when defining
<gener1c>
you canty
<gener1c>
ur right
<apeiros_>
ah
<gener1c>
i meant
<gener1c>
when defining
<gener1c>
def methond([1,2,3]) has no meaning
<Mon_Ouie>
neither does def method(1, 2, 3) mean something
<gener1c>
def methond([var1,var2,var3])
<gener1c>
nevermind , im confused
<Mon_Ouie>
def foo((a, b, c)); puts b; end
<Mon_Ouie>
foo [1, 2, 3]
<Mon_Ouie>
But then if you have a finite amount of arguments you should be using foo(a, b, c) directly
<Johnnus_>
How can i name a belongs to relationship in mongoid? For example a User model and a Car and i want to have a belongs_to :user, :as => :owner in car. How can i do that in mongoid?
Pip joined #ruby
Pip joined #ruby
_iori_ joined #ruby
<shevy>
anonymouse! he wrote anonymouse!
<shevy>
a mouuuuse!
<shevy>
squeaaaaak
<gener1c>
anonymoanonymous
eerdogan joined #ruby
Vendethiel joined #ruby
kmmndr joined #ruby
Jake232 joined #ruby
robyurkowski joined #ruby
bosphorus joined #ruby
kmmndr joined #ruby
emmanuelux joined #ruby
Knodi joined #ruby
kmmndr joined #ruby
jtdowney joined #ruby
Draco_ joined #ruby
Azure_ joined #ruby
Natch| joined #ruby
Pip joined #ruby
Pip joined #ruby
tk__ joined #ruby
<linduxed>
how is this line wrong ?
<linduxed>
if ( a == b ** b == c )
<apeiros_>
it is probably parsed as: (a) == (b**b) == (c)
looopy joined #ruby
bier|tp joined #ruby
<apeiros_>
and that in turn is ((a) == (b**b)) == (c)
<apeiros_>
but how about you tell us how it is wrong?
bier joined #ruby
<linduxed>
well i got some errors, but i fixed it (i think) by writing "if (a == b) ** (b == c)"
grekko joined #ruby
<linduxed>
undefined method `**' for true:TrueClass :-S
<linduxed>
isn't ** ruby's logical and?
<apeiros_>
in that case, it obviously is (a == b)**b
<apeiros_>
yeah, later down it says ** - logical and
<linduxed>
should have followed my intuition and went for && ....
<rippa>
that's messed up
Ch4rAzZz joined #ruby
<rippa>
also While and stuff is capitalized
<rippa>
that's not gonna work
<apeiros_>
commented…
<apeiros_>
bad article IMO.
matadon joined #ruby
<matadon>
Any idea what method you need to implement on the class being enumerated over for Enumerable#grep to work?
<matadon>
E.g., regexp matching on a Class
<apeiros_>
===
<Mon_Ouie>
Nope, it does it the other way around
<Mon_Ouie>
it calls pattern === element, not element === pattern
<matadon>
Mon_Ouie: Exactly.
<rippa>
matadon: #each , I guess
<matadon>
rippa: No, that just implements the iteration part. I want to create a class Foo that can match against a regexp (e.g., pattern.match(Foo.new))
<Mon_Ouie>
You just need an object whose === method can be called on what you're iterating over
<matadon>
Mon_Ouie: So I have to munge the pattern provided to grep?
<matadon>
Or is there some method I can implement on the enumerated object so that pattern.match(...) will work on it?
<Mon_Ouie>
It just depends on what pattern === does
<Mon_Ouie>
(it does not call match, only ===)
<apeiros_>
matadon: you mean you have [YourClass.new, YourClass.new].grep(/pattern/) and you want the YourClass instances be matched?
<apeiros_>
you'd need YourClass#to_str
<matadon>
Yep.
<matadon>
to_str
<matadon>
Thanks, to_s wasn't playing ball.
<apeiros_>
be aware though, that to_str technically means that your object has one true string representation
* apeiros_
wonders why ruby doesn't use a coerce mechanism there…
<matadon>
apeiros_: Thanks! The string representation won't be a problem for this class.
<linduxed>
how do i split that up to multiple lines?
<linduxed>
i can't split up the condition can i?
<Mon_Ouie>
You can have a newline after ||
<linduxed>
oh, that does it then
<linduxed>
rippa: pretty true...
<yxhuvud>
you can also use \
<matti>
Mon_Ouie: Hey there :)
<linduxed>
can i have a newline after if?
<Mon_Ouie>
'alut matti :)
<Mon_Ouie>
Yes, it knows there needs to be one expression after if
<linduxed>
ok
<Mon_Ouie>
And that the condition is only one expression
rickmasta joined #ruby
Pip joined #ruby
Pip joined #ruby
srji joined #ruby
CannedCorn joined #ruby
looopy joined #ruby
macmartine joined #ruby
xpot-mobile joined #ruby
Hellojere joined #ruby
sorin joined #ruby
chrisbdaemon joined #ruby
emptyflask joined #ruby
yxhvuud joined #ruby
<chrisbdaemon>
trying to write a class for aes encryption with openssl.. I have this: http://pastebin.com/zUSzf0DJ when I use my class to encrypt and decrypt a file, the decryption works sometimes but other times it returns an error about the "wrong final block length"
<chrisbdaemon>
did I forget something or leave something out?
eldariof joined #ruby
Telling joined #ruby
crescendo_ joined #ruby
kassien_ joined #ruby
iband joined #ruby
kalusn joined #ruby
daidoji joined #ruby
wyhaines joined #ruby
robyurkowski joined #ruby
pabloh joined #ruby
flip_digits joined #ruby
ThinkSocrates joined #ruby
tomhsx joined #ruby
tatsuya_o joined #ruby
felipegb joined #ruby
wyhaines joined #ruby
bosphorus_ joined #ruby
<chrisbdaemon>
got it, there was a problem with encoding, opening the file both times with "b" in the mode fixes it :) the encoding was screwing up my slicing the iv off the front of the file
chrisbdaemon left #ruby
<apeiros_>
eeeew windows
ThinkSocrates left #ruby
Adman65 joined #ruby
closedbracket joined #ruby
kartouch joined #ruby
mxweas_ joined #ruby
banister`movie joined #ruby
atmosx joined #ruby
<atmosx>
hello
<atmosx>
can you tell me if this sqlite3 string has errors? I'm concerned about the 1st '?' … which should be sqlite3 table name=> db.execute('INSERT INTO ? (username, date, content, content_id) VALUES(?,?,?,?)', @userid, username, time, text, text_id)
<atmosx>
it comes out with an error
fladamd joined #ruby
atmosx left #ruby
atmosx joined #ruby
jr00n joined #ruby
pantsman joined #ruby
pantsman joined #ruby
cbuxton joined #ruby
yellow5 joined #ruby
IrishGringo joined #ruby
Cervajz joined #ruby
workmad3 joined #ruby
djr_ joined #ruby
benja-M-__ joined #ruby
thecreators joined #ruby
qanyan joined #ruby
goodieboy joined #ruby
dbgster joined #ruby
<qanyan>
Hello everyone, have a question. Please check following paste - http://www.pastie.org/2925102 Not quite sure why we've converted symbols to strings to make that include check? It could work without it
mikepack joined #ruby
<rippa>
qanyan: because if you used symbol it would match regardless of existence of method with same name
Axsuul joined #ruby
xol joined #ruby
jay_zawrotny joined #ruby
<qanyan>
rippa, was testing it in irb and it returned false but once I've made test.rb file and executed it there - returns true even for nonexisting method. Why is it happening?
jr00n left #ruby
mxweas_ joined #ruby
Cervajz joined #ruby
jonathanrwallace joined #ruby
tomzx joined #ruby
Annaeus joined #ruby
<Annaeus>
Simple question: I have an idea for a web based app, my only programming experience is c++ (ten years ago) I've narrowed my language of choice down to Ruby and Python, any thoughts?
sullx joined #ruby
<rippa>
use either
Jake232 joined #ruby
<shellox>
Annaeus: ruby is better imho
<shellox>
i really like the sinatra web framework for ruby
<rippa>
sinatra sure is fun
sdavis joined #ruby
<Brozilla>
and really simple
<Annaeus>
shellox: yeah I'm leaning that way, just because I found the rails framework, haven't found a framework for python yet (although I'm sure they are out there)
<Afal>
Django?
<rippa>
Django
<shellox>
ruby: rails or sinatra
<shellox>
python: bottlepy or flask
qanyan left #ruby
<shellox>
i dont like rails much to be honest
<rippa>
rails is too invasive
<rippa>
monkeypatches everywhere
<shellox>
too bloated for me
<Annaeus>
what makes sinatra better than rails?
<Brozilla>
i'd go with sinatra if you're just starting. i started with rails right away and it's really confusing if it's your first experience with ruby
<shellox>
and too much changes with every version
<Annaeus>
interesting
<shellox>
Brozilla: i code ruby for 1 year now. I started with sinatra for web stuff then and try tried rails, but i failed soo hard ;)
<shevy>
what is special about sinatra
<shellox>
Brozilla: i really asked myself 'wtf, where to add this?. Which woulb be the correct place'
<Brozilla>
haha, exactly :p
<shellox>
shevy: i like it because it's simple and powerful
<Brozilla>
sinatra is really really simple
<Annaeus>
I'm guessing sinatra is open source?
<Brozilla>
it's basically just get '/page/:id' do [your code] end
<shellox>
Brozilla: keep things simple is good imho
<Annaeus>
thanks, I was just about to google, since it was not on Git
<Brozilla>
it is
<shellox>
rails started simple but turned in the wrong direction imho
<shellox>
i need 5% of the rails framework, so it doesnt make sense to ship a product with the other useless stuff, which i dont use
<shellox>
Brozilla: and it's so fucking hard to write a rails app w/o a database ;)
<Brozilla>
never attempted, but i can see why
<shellox>
maybe it got easier now, im not sure
<shellox>
i tried it with the release of rails3
jbw joined #ruby
marknyc joined #ruby
tmart joined #ruby
looopy joined #ruby
zommi joined #ruby
LittleBill902 joined #ruby
fladamd joined #ruby
<Annaeus>
shellox and Brozilla: thanks for your help, I've decided to go with Ruby. Still up in the air on sinatra versus rails though, I'll take you at your word that sinatra is better, but rails has a bigger community with more help
fladamd joined #ruby
<fladamd>
what does -> mean?
<fladamd>
i.e. ->(value) { TagList(value) }
<rippa>
I'd say sinatra is easier to get into
<rippa>
fladamd: it's alternate syntax for lambda
<fladamd>
ah, thank you!
<rippa>
lambda {|value| TagList(value)}
<rippa>
means exact same thing
tayy joined #ruby
petercoulton joined #ruby
sythe joined #ruby
sythe joined #ruby
jwmann joined #ruby
jwmann joined #ruby
jwmann joined #ruby
nyuszika7h joined #ruby
cyri_ joined #ruby
tmart joined #ruby
peterhil` joined #ruby
swarles joined #ruby
friskd joined #ruby
<swarles>
how do you get arguments like the sprintf method that has a variable ammount of methods?
<swarles>
like you can do sprintf("hello %s %s, how are you today? I am %s", first_name, last_name, my_name)
<yfeldblum>
in case anyone was looking for some advanced ruby tricks :P
tomhsx joined #ruby
<shevy>
what is that doing
xol joined #ruby
<daidoji>
just what he said
<yxhuvud>
yfeldblum: it not only has to answer to to_proc, the method actually has to return a Proc.
<shevy>
it returns 3
<daidoji>
cause thats how its defined homie
<shevy>
awesome
ryanf joined #ruby
Gazler joined #ruby
<yfeldblum>
yxhuvud: that's right
<yfeldblum>
you can also pass nil, so that this trick works: `call_some_method(3, 4, 5, :hi_there, &(Proc.new if block_given?))` whether or not a block was passed in to the current code
<yfeldblum>
but please don't do that, it's ugly :P
IrishGringo joined #ruby
<daidoji>
is anyone in here familiar with jruby? and even if you're not how does the rspec process go?
<daidoji>
I should just be able to install the rspec gem and then run rspec with no arguements right?
<daidoji>
after building from source i mean
<yfeldblum>
i believe rspec requires arguments: you have to pass in the list of files/directories to run ... `rspec spec` or `rspec spec/models` or `rspec spec/models/post_spec.rb`
Draco_ joined #ruby
<daidoji>
but I've got the process right correct?
austinbv joined #ruby
<daidoji>
I build from the source and get the ruby executable (or jruby.jar in this case), then run 'rake spec' or 'rspec spec' and it should work
rickmasta joined #ruby
alexisd joined #ruby
SolarisBoy1 joined #ruby
<alexisd>
hello, I'm looking for a server to deploy some rails apps, Heroku and Slicehost seems the cheapest ones, but they are quite expensive
<alexisd>
I dont want to pay 150$ a month, do I have some alternatives plz?
airhorns joined #ruby
tomzx joined #ruby
<k0i>
you could get a vps.. linode is like $20
<daidoji>
alexisd, if you have to ask that question, you should probably just pay the money (imo)
<daidoji>
it'll be less hassle for you in the long run
<swarles>
def my_method(first_arg, second_arg, *args) How would i go about using that glob?
<alexisd>
daidoji, I checked linode but it seems some poor on documentation, and I cant try it
<alexisd>
do you use it ?
<alexisd>
oops I mean k0i
<alexisd>
daidoji, I dont have 2000$ a year
LittleBill902 joined #ruby
<alexisd>
I now use free heroku account that is superb, but is like 200$ a month if I go commercial :(
<yfeldblum>
rackspace cloud is $11/mo for the smallest slices
<daidoji>
alexisd, I mean I myself would/have run VPSs for some of my smaller projects
<daidoji>
but its a matter of experience
<yfeldblum>
heroku has a free tier
<daidoji>
I can do everything from linux on up to rails
<daidoji>
so if you feel like you can do that then go with a VPS or a cloud solution thats cheap
<alexisd>
yfeldblum, on https://cart.rackspace.com/cloud/ i check cloud servers and cloud files, that is 11$, but it says cloud sites starts from 150$ a month
<alexisd>
I wonder why that huge difference
<daidoji>
but its usually pretty cost effective just to let Engine Yard or Heroku do all the heavy lifting while you focus on your app
<daidoji>
because you'll end up spending that much in support costs anyways
<alexisd>
daidoji, yes heroku is amazing, but quite expensive :(
<alexisd>
I wonder why rails host is so more expensive than php
<daidoji>
alexisd, well because the php host doesn't have to do anything
<daidoji>
you slap modphp on an apache box and you're set
<daidoji>
the rails guys do a lot more to work with you to enhance your rails app
<daidoji>
I mean if you're really really strapped for cash, go with the VPS solutions
<daidoji>
but you'll have to support everything yourself
<alexisd>
this pricing is really huge problem on rails
<alexisd>
daidoji, you have heroku account?
<mattp_>
how do i test actionmailer?
<daidoji>
alexisd, I do but only the free version
<mattp_>
i generate a Mail::Mesage and call .deliver
<mattp_>
no errors outputed
<yfeldblum>
alexisd: why are you looking at cloud sites? it doesn't support rails
<mattp_>
but im not receiing the email
<alexisd>
yfeldblum, the support, I have already deploy rails 3 on them
<alexisd>
they*
<yfeldblum>
alexisd: last i checked, they used to support rails on cloud sites but they were discontinuing that
<alexisd>
yfeldblum, what are u saying? We talk about Heroku
<dabaR>
That's the tut I followed, and it works fine.
<dabaR>
But I've been installing this for a while now
<dabaR>
Like, debugging, testing, etc.
dv_ joined #ruby
emocakes joined #ruby
dcarper joined #ruby
<dabaR>
So the latest dep I added doesn't work any more
<dabaR>
I feel that it is most likely that it is caching somehow something
<dabaR>
Cause that dep looks like all the others in the gemspec
notbrent joined #ruby
robyurkowski joined #ruby
ernestocid joined #ruby
<notbrent>
hi, i was wondering if anyone knows of a way to get a sequence of numbers regardless of whether it is incrementing or decrementing.. what i mean is, (1..3).each .. etc works, but (3..1).each etc does not, how could i make either case work?