<drbrain>
countskm: sometimes I have class Host and class Host::Linux < Host
<countskm>
gotcha - that makes sense tx
<rking>
countskm: It can be Ok, but it is ever so slight a smell that something is not being named perfectly well. I wouldn't refuse to do it, but I'd pause to check if it was the right name.
<countskm>
yeah - i have been trying to stay at one level as much as possible - guess it depends too how many different times i subclass
Clordio has joined #ruby-lang
<countskm>
i just "yarded" my project and it really started to make me think about this :-)
<drbrain>
countskm: I think my source tree looks cleaner if it's lib/host/lunix.rb vs lib/host.rb; lib/linux_host.rb
<countskm>
i agree it looks cleaner to me too
Joeysomo has joined #ruby-lang
<countskm>
but what would u name the class LinuxHost or HostLinux?
qpingu has joined #ruby-lang
<countskm>
i know there is no wrong/right but your style u would use?
<countskm>
i know im thinking about this too much ;-)
mdel has joined #ruby-lang
<countskm>
ah right u would use namespace for it - i got it
<drbrain>
if you're parent class is Host, I think Host::Linux is better than HostLinux
<countskm>
yeah gotcha
<erikh>
hello rubyists
<erikh>
entertain me
<mistym>
erikh: What entertains you?
<countskm>
yu-gi-oh
<drbrain>
erikh: I am writing a spell-checker for rdoc
<erikh>
drbrain: awesome!
<erikh>
i'm learning clojure!
<drbrain>
that sounds nice
<erikh>
it's pretty neat, but royally breaking my brain
<countskm>
can i have both Host and Host::Linux as classes - i am getting an unitiaizled constant error in my rspec and i have the suspiscion that Host must be a module?
<drbrain>
countskm: you have to require 'host' before 'host/linux'
<drbrain>
you can do that either by adding require 'host' to the top of the file creating Host::Linux
<drbrain>
or you can do that by adding require 'host/linux' to the bottom of the file creating Host
<countskm>
tx - lemme muck w/ it
<countskm>
boom - worked - thats why u get paid the big bucks drbrain ;-)
<drbrain>
ha!
<countskm>
appreciate it
woollyams has joined #ruby-lang
<drbrain>
that's what we're here for
shevy has joined #ruby-lang
UziMonkey has joined #ruby-lang
UziMonkey has joined #ruby-lang
UziMonkey has joined #ruby-lang
<countskm>
man thats the best feeling when rspec passes :-)
<countskm>
perhaps a false sense of security but ill take it :-)
<drbrain>
I'm a minitest/unit person myself
<bougyman>
bacon, here.
<bougyman>
because: who doesn't love bacon?
<countskm>
yeah i like minitest - its nice
<bougyman>
you can almost taste the grease when bacon passes.
<countskm>
i came into ruby recently and just learned rspec first but saw minitest a couple weeks ago and it looks spot on
<bougyman>
win
denysonique has joined #ruby-lang
* countskm
is a turkey bacon fan
<bougyman>
fail
<countskm>
lol
<erikh>
turkey bacon? that's just taking all the fun out of it.
<countskm>
man i love that stuff - i microwave it for like 25 seconds - awesome!
<lianj>
bacon in the mircowave?
<bougyman>
blasphemer
andrewhl has joined #ruby-lang
<erikh>
oh man my insides are hurting just thinking about that.
<countskm>
i better stop while im behind :-)
<erikh>
heh1
nif has joined #ruby-lang
Teddy2st_ has joined #ruby-lang
PsiliPharm has joined #ruby-lang
petercooper has joined #ruby-lang
t has joined #ruby-lang
seanstickle has joined #ruby-lang
kvirani has joined #ruby-lang
nif has joined #ruby-lang
Teddy2steper has joined #ruby-lang
lpdahito has joined #ruby-lang
<rue>
Tofurkey bacon
neoesque has joined #ruby-lang
nofxx has joined #ruby-lang
<rue>
Although I also like non-crispy bacon, the rare times I do have some
mistym has joined #ruby-lang
<lpdahito>
Hey guys! This might seem like a noob question but i would like to modify a gem... I got the source by cloning it from github... I would like to make my changes to it but im not able to test them since every time i try to load the code... i get a loading error... Does the gem have to be installed? I thought i could work directly from the "lib" directory inside the package... To be more precise... I'd like to bring some modifications to th
<lpdahito>
"Garb" gem... this is where you can find it: https://github.com/vigetlabs/garb When i type this command in my console being in the "lib" directory: ruby garb.rb I get this error: `require': no such file to load -- garb/support (LoadError) What am i doing wrong
<lpdahito>
??
Transformer has joined #ruby-lang
Zolrath_ has joined #ruby-lang
<mistym>
lpdahito: require loads code which is in your load path, which is stored in the $LOAD_PATH and $: variables. The working directory is *not* in the load path, so it's not looking for the downloaded copy of the repo you're using.
<drbrain>
lpdahito: ^^ adds your modified garb to $LOAD_PATH ($:)
fgomez has joined #ruby-lang
jaisoares has quit [#ruby-lang]
nif has joined #ruby-lang
gnufied has joined #ruby-lang
shtirlic_ has joined #ruby-lang
<lpdahito>
@drbrain thx a lot
rking has joined #ruby-lang
<lpdahito>
drbrain how would you go about modifying a gem?
<lpdahito>
drbrain would you install it or would you work from a cloned repo and then install it?
<drbrain>
lpdahito: I fork it, run the tests, write a new test, make the test pass, then use ruby -I to try it in my Real Program
<drbrain>
I rarely install it
delinquentme has joined #ruby-lang
<delinquentme>
Threads in ruby anyone?
<lpdahito>
drbrain thx a lot!
<drbrain>
delinquentme: yes, but I almost use Queue or some other higher abstraction
<drbrain>
almost always
<delinquentme>
drbrain, but this is what I think it is right
<delinquentme>
multithreading in ruby?
<delinquentme>
taking advantage of multicore processors?
<delinquentme>
and do you have a nice exhaustive tutorial for it?
<drbrain>
delinquentme: the interpreter can't run on multiple threads at this time
<mistym>
delinquentme: Unless you use jruby or another alternate interpreter
<delinquentme>
so what are the advantages then?
<drbrain>
delinquentme: in MRI, multithreading is best used when you are IO bound, not CPU bound
<drbrain>
delinquentme: otherwise, you use multiprocess
<delinquentme>
Often the simplest way to do two things at once is by using Ruby threads. These are totally in-process, implemented within the Ruby interpreter. <<< ?
<delinquentme>
IO bound would be operations like waiting for a webpage to resolve right?
<drbrain>
delinquentme: so long as you're not CPU bound, that will be fine
<drbrain>
CPU hungry ruby on MRI does not work well
<drbrain>
on JRuby it is fine
<drbrain>
correct
<drbrain>
if you want to read web pages and do a small amount of processing, MRI is fine
<delinquentme>
and an interpreter is just as its namesake .. its going to run the same code right?
<delinquentme>
MRI vrs some JRuby interpreter
<drbrain>
if you want to calculate lots of primes, use JRuby
<drbrain>
JRuby and MRI run the same code
<delinquentme>
so much complexity
<drbrain>
but JRuby is much better at CPU hungry threads
<delinquentme>
wild
Nisstyre has joined #ruby-lang
nif has joined #ruby-lang
<delinquentme>
other examples of waiting for I/O would be database searches ?
<delinquentme>
i mean such as waiting for SQL queries to return
<drbrain>
yes
<drbrain>
anything involving sockets or files
<drbrain>
it's my dinner time
<mistym>
delinquentme: Useful for waiting in general. E.g. I had smth that was waiting on keyboard input from the user, so it was trivial to stick the keyboard poller on a separate thread where it doesn't block
<delinquentme>
ohhh
<delinquentme>
wow.
<delinquentme>
i could used this for micro controllers =]
<delinquentme>
mistym, awesome example
igotnolegs has joined #ruby-lang
gokul has joined #ruby-lang
nif has joined #ruby-lang
<delinquentme>
should I worry about creating too many threads?
nif has joined #ruby-lang
<countskm>
as long as its under (2^64) - 1 u should be fine :P
<delinquentme>
check LD
jxie has joined #ruby-lang
nif has joined #ruby-lang
<rue>
Check 1-2
RomyRomy has joined #ruby-lang
<mistym>
rue: ?
<rue>
1-2, 1-2
nif has joined #ruby-lang
<delinquentme>
any ideas on why i might be getting " undefined method `keys' for nil:NilClass (NoMethodError) " for this code: https://gist.github.com/2324632
chessguy has joined #ruby-lang
<rue>
Because you're invoking nil.keys
<rue>
for…in, seriously? :P
<rue>
Also, you probably have a line number or summit?
<imperator>
rue, where is he call .keys?
<rue>
Could be anywhere, ergo ^^
<imperator>
that example is from the pickaxe i think
<delinquentme>
you mean the error its throwing right?
<erikh>
man, screen sharing on the mac is stupidly easy
<imperator>
hm, dunno about trying to return out of a thread block, looks like a no-no
RomyRomy has joined #ruby-lang
<imperator>
i'd share my screen, but the naked cheerleader i'm using as a background might be off putting to some
<delinquentme>
nope ! im of age
<delinquentme>
so i should just not use returns huh
<imperator>
delinquentme, well, what do you want it to do? just skip to the next journal entry?
senthil has joined #ruby-lang
<imperator>
first, i'd try to figure out what the exception is that it's raising
<imperator>
and, rescuing LocalJumpError is....probably not a good idea
<imperator>
erikh, well, you gonna tell us how?
<delinquentme>
imperator, well I've got multiple versions of this ... ideally I've got a recursive which runs through once ... notes the ones which break and re-run them later .. basically the ones which break are because i hit throttling on google ( i think )
<delinquentme>
but given a delay of 2 seconds before starting recursion its all gravy
<delinquentme>
SO... ideally the breaking ones .. id love to throw into an array and run through them once again
<imperator>
i guess i'm not sure what advantage threads provide if you're being throttled anyway
<delinquentme>
imperator, the thing is its really sporadic
<delinquentme>
sometimes it runs through entirely without hitting the cap
<imperator>
you could always sleep + retry
<imperator>
just be careful you don't retry indefinitely
RORgasm has joined #ruby-lang
<erikh>
imperator: click system prefs, sharing, "share screen"
<erikh>
then connect to it in the finder
<erikh>
DONE
sharkbyteusa has joined #ruby-lang
takaokouji has joined #ruby-lang
senthil has joined #ruby-lang
<delinquentme>
A mutex is often used when updates to shared data need to be atomic. <, can someone define "atomic "
<shevy>
kiddorails btw you can omit the "==true" part
<shevy>
if variable
<shevy>
do_something
takaokouji has joined #ruby-lang
rohit has joined #ruby-lang
RORgasm has joined #ruby-lang
rolfb has joined #ruby-lang
morozovm has joined #ruby-lang
rohit has joined #ruby-lang
mikeric has joined #ruby-lang
baniseterfiend` has joined #ruby-lang
burgestrand has joined #ruby-lang
benanne has joined #ruby-lang
deobald has joined #ruby-lang
ifaria has joined #ruby-lang
dous has joined #ruby-lang
radoen has joined #ruby-lang
<radoen>
hi all
<radoen>
i have a trouble whit a module when lunch them interpreter says me ./beef.rb:116:in `<main>': uninitialized constant BeEF::Core::Websocket (NameError) here the code http://pastebin.com/QsqbksHp
<radoen>
where is the problem? line 116 in beef.rb is just BeEF::Core::Websocket.initialize
Gekz_ has joined #ruby-lang
Gekz_ has joined #ruby-lang
kiddorails has joined #ruby-lang
rippa has joined #ruby-lang
apeiros_ has joined #ruby-lang
judofyr_ has joined #ruby-lang
hirotoshi has joined #ruby-lang
<manveru>
radoen: typo?
Defusal has joined #ruby-lang
Defusal has joined #ruby-lang
indeterminate has joined #ruby-lang
Guest12345 has joined #ruby-lang
rohit has joined #ruby-lang
Guest12345 has joined #ruby-lang
fjfish has joined #ruby-lang
Guest12345 has joined #ruby-lang
wski has quit [#ruby-lang]
RORgasm has joined #ruby-lang
<erikh>
hrm
<erikh>
imperator: if/when you're around, Sys::ProcTable doesn't seem to report memory stats on os x.
<brahmana>
It was working fine a little while ago when I was doing something similar in one of my scripts (running as a daemon) and all of a sudden I started seeing error messages in the daemon log about the file being empty. !
<shevy>
and .path on your tempfile object shows what?
<brahmana>
this - /tmp/temp-file-test20120407-4281-ljvpuv
<erikh>
you need to flush after write()
<irmb>
Hi guys - I have a quick, non ruby question - could any of you mac os x guys recommend a good irc client? I found Colloquy, but it isn't mIRC enough for me, and no other client seemed that up to date/maintained/loved
<erikh>
you can do that by closing the tempfile or calling flush manually.
<erikh>
irmb: I like linkinus
<erikh>
you can find it on the app store.
<brahmana>
erikh: oh.. that was it.. !
<brahmana>
erikh: If not flushed or closed, when would it be done automatically, if at all?
<irmb>
I'll check it out, erikh. Thanks!
<brahmana>
And I believe this is not specific to Tempfile, but applies to file i/o in general, right?
<erikh>
brahmana: the short answer is, "whenever the system feels like it"
<erikh>
i've gotta bail
<brahmana>
:) .. ok.. so it's the kernel and not the interpreter
<brahmana>
well, thanks erikh
<rue>
My kernel is a Tempfile
<shevy>
yay!
<shevy>
rue rubyOS !
codewrangler has joined #ruby-lang
<rue>
Hm, it's gon
<shevy>
:(
<shevy>
well it was great while it lasted still
enebo has joined #ruby-lang
Asher has joined #ruby-lang
mistym has joined #ruby-lang
irmbrady has joined #ruby-lang
nataraj has joined #ruby-lang
yaroslav has joined #ruby-lang
rushed has joined #ruby-lang
irmbrady has quit ["Biya."]
seanstickle has joined #ruby-lang
jperry has joined #ruby-lang
tla has joined #ruby-lang
irmbrady has joined #ruby-lang
Nisstyre has joined #ruby-lang
ridders24 has joined #ruby-lang
RORgasm has joined #ruby-lang
<ridders24>
hi guys
<mistym>
Hi ridders24
<ridders24>
hows your weekend going?
<rue>
It's weekend?
<ridders24>
was the last time i checked?!
kiddorails has joined #ruby-lang
kain has joined #ruby-lang
elalande has joined #ruby-lang
<ridders24>
im stuck, Im trying to get my script to work, but appear to be having an issue with line 7 and I cant seem to get my head round linking up the search pattern with searching a drive for a particular filename: http://pastie.org/3744708
ericlalande has joined #ruby-lang
ericlalande has quit [#ruby-lang]
<anildigital>
What if we want to write tests which outputs something on console.. and i want to validate it from tests?
<anildigital>
is there any class which help me..
<rking>
anildigital: Wait, are you wanting to mock that interaction, or /actually have that interaction/?
<anildigital>
rking: I have a class .. when I initialize it with some arguments and call a method on that.. it does some network activity and prints to console
<anildigital>
now I want to verify whether it prints 'Yup' or 'Nope' on console..
<rking>
anildigital: Do you know about mocking?
<anildigital>
rking: yup
<anildigital>
little bit :)
<rking>
anildigital: K, that's about all you need to know. =) Interfere with its printing method calls -- capture what it does, and then test that.
jmeeuwen has joined #ruby-lang
<anildigital>
hmm. okay.. rking let me share my code in few minutes..
<anildigital>
looks like I am doing it totally wrong..
<mistym>
ridders24: What exactly is the search pattern you're trying to do here?
<mistym>
ridders24: Are you trying to search the entire drive?
<ridders24>
Basically I have a spreadsheet that in 2 colums with contain values such as 1234 1234-12-ABC-1-2 or 1234 ABC-1-2
<ridders24>
it also needs to search the specified drive letters
<anildigital>
rking: there?
<rking>
anildigital: Looking at it.
<anildigital>
ok :)
<rking>
anildigital: Is there anything to spec_helper ?
<anildigital>
rking: there is nothing much in it.. only require 'doesfollow' and require 'rspec'
<rking>
K.
fukushima has joined #ruby-lang
<rking>
anildigital: And rest_client ?
<anildigital>
it's a gem I included.
<rking>
ERROR: Could not find a valid gem 'rest_client' (>= 0) in any repository
<rking>
Ahh, rest-client
<ridders24>
mistym: did that make sence?
Indian has joined #ruby-lang
<mistym>
ridders24: Not quite sure I get how that relates to the sample code you pasted? Are you searching the drive for the value you're deriving from the spreadsheet?
<anildigital>
rking: are you trying to run it?
<rking>
anildigital: Yep.
<anildigital>
let me know if you require anything.. you should be able to run it fine.. comment lines like require 'doesfollow/version'
Indian has joined #ruby-lang
<rking>
anildigital: K, I was planning on that.
<ridders24>
the pattern /[A-Z0-9-]+/ finds what im looking for in the spreadsheet, but I dont know how to then get the script to search for example F: for a file with a filename that matches that pattern with an extention of .txt
<rking>
anildigital: 1) I don't have the ruby dev stuff really set up (so I'm having to gem install rspec, etc.), 2) I'm still kind of a noob, so I'm going to have to actually play with it to get a solution.
<anildigital>
rking: hmm okay..
<rking>
ridders24: Yeah, I think DOS cd does something weird with drive letters.
<mistym>
ridders24: Ahh, I see.
<ridders24>
mistym: is that better? the code was to show you what I have so far
<mistym>
ridders24: Yeah, I get you now.
<rking>
ridders24: Like, for example, you can type a bare drive letter and it switches you to that. It's not truly a directory, I think cd only has a cheat for it.
<mistym>
For searching the contents of a drive, I'd recommend using Find.find instead of globbing in Dir[].
<ridders24>
mistym: what about linking the pattern in?
<mistym>
ridders24: You should save your pattern to a variable. Then, in Find's block, you can see if a file a) matches the same pattern, and b) has the .txt extension.
<rking>
ridders24: I think you're going to have to require 'Win32API'
jperry has joined #ruby-lang
<ridders24>
mistym: so like variable = /[A-Z0-9-]+/ like that?
m3nd3s has joined #ruby-lang
<mistym>
ridders24: Yes! Then you can string.match variable, or string =~ variable
VegetableSpoon has joined #ruby-lang
kiddorails has joined #ruby-lang
<ridders24>
mistym: sorry if some of the stuff i ask if simple, I've only been doing ruby for 2 weeks,
<mistym>
So if file =~ variable and file =~ /\.txt$/, then you know it's a .txt that matches your pattern
<rking>
anildigital: Do you have to do anything special to run rspec tests? ruby doesfollow_spec.rb is not doing anything.
<mistym>
ridders24: No worries!
<anildigital>
rking: you have to install rspec gem
<rking>
anildigital: I have that.
savage- has joined #ruby-lang
<mistym>
( /\.txt$/ checks to see if the file has a pattern that matches ".txt" at the end of the line. It won't match, say, foo.txt.bar)
<anildigital>
rking: then run it like this.. rspec doesfollow_spec.rb
<rking>
anildigital: k, now I've got something I can work with.
<ridders24>
mistym: ok cool, I'll play around with the code and the stuff you have given me and I'll see what I get. I'll probably be back in a mo
tjadc has joined #ruby-lang
countskm has joined #ruby-lang
<mistym>
ridders24: OK! Lemme know if you need any more help
<ridders24>
mistym: cheers man
<rking>
anildigital: When I look up rspec mocks, I see stuff about "double(foo)", but you're using "mock(foo)"... where is that coming from?
<anildigital>
rking: double is nothing but mock right? i.e. test double
<rking>
anildigital: I don't know. I'm looking at the results of a Google search and only seeing stuff about double()
<rking>
Maybe they are aliases
<anildigital>
rking: ok
datanoise has joined #ruby-lang
<rking>
anildigital: Yes, they are the same thing.
<anildigital>
:)
<rking>
anildigital: Also stub(), if you really want to mix it up. =)
jaisoares has joined #ruby-lang
<kiddorails>
andrewvos: Hey, I was looking this https://github.com/txus/brainfuck . How do they generate this environment for a ruby program?
<rking>
anildigital: Forgive me for being slow, we'l get there.
<anildigital>
okay..
<kiddorails>
How did bin, lib , gemfile etc came there. All I know is simple .rb coding and that's all.
<kiddorails>
Have to look rspec, but need help here to understand, how actually that is happening.
<rking>
anildigital: OK, let's start with the very first test. Now that I'm starting to get the picture, I don't think it does anything.
<anildigital>
rking: right..
<rking>
anildigital: Let me put it this way, if you change its first line to users = mock(1234) #... it still passes.
<rking>
anildigital: What you want to do is not mock the method under test, but the parts that method would call. In the case of doesfollow, you'd want to mock out Doesfollow#get_resource_json
<anildigital>
rking: wait..
<anildigital>
giving you another code..
<rking>
anildigital: K
<rking>
anildigital: What I am saying is there is nothing you could put in doesfollow.rb that would make the 'it "says anildigital follows defunkt is true"' test fail.
NinoScript has joined #ruby-lang
<anildigital>
rking: yeah.. it's totally wrong.. I should not mock the class.. I should just stub the method which decided true and false..
<anildigital>
and other behavior should be live from code..
<anildigital>
and I should assert against result..
<rking>
anildigital: Wait, what do you mean "the method which decided true or false"?
<rking>
anildigital: The only thing I would want to see mocked in this is get_resource_json
<anildigital>
rking: I mean.. instead of doing network activity to check whether one follows another.. I should mock / stub that..
<anildigital>
and everything should be tested against that..
<anildigital>
rking: yeah.
<rking>
anildigital: Yep, make it return a different fake ids list depending on the arg.
<imperator>
erikh, i'm back, i'll take a look
<rking>
anildigital: Possibly also make it do some assertions inside there, to verify that the arg is getting passed as it should.
<anildigital>
rking: yup doing the same
tla has joined #ruby-lang
Supervisor has joined #ruby-lang
<Guest77406>
hi
<anildigital>
rking: I should share you updated code...
<Guest77406>
what is the most simple way to login into a webpage (i.e. facebook.com) with ruby?
<Guest77406>
i dont want to communicate with graph-api etc. just wanna login into fb
<rking>
Guest77406: I don't really have enough experience in this area to give you a supergood answer, but I do know that Facebook expects you to use their actual API, not home-brewed HTTP requests.
<Guest77406>
thank but i think rfacebook is little bit out dated :-/
rippa has joined #ruby-lang
<rking>
Guest77406: Hrm.. last update 2008. =\ Does it no longer work?
<Guest77406>
i will give it try
mechanicles has joined #ruby-lang
datanoise has joined #ruby-lang
bglusman has joined #ruby-lang
hirotoshi has joined #ruby-lang
hirotosh_ has joined #ruby-lang
nofxx has joined #ruby-lang
VegetableSpoon has quit ["Leaving"]
Sailias has joined #ruby-lang
nif has joined #ruby-lang
kain has joined #ruby-lang
flexd has quit ["WeeChat 0.3.6"]
naz has joined #ruby-lang
ridders24 has joined #ruby-lang
<ridders24>
mistym: sorry im back, I'm struggling to understand the example of find.find and im going round in cycles.
<mistym>
ridders24: What're you having trouble with?
<ridders24>
mistym: all of it lol, what was the reason for changing to find.find instead of what I have got?
<mistym>
OK! Well, basically Find.find takes a path, and then returns you each filesystem item within that path recursively. The code in your block will be executed once for every file it finds.
<mistym>
That gives you a good way to run code which checks to see if the files/directories it finds match what you're looking for.
<ridders24>
mistym: ok that makes sense, now I just need to understand the code and how to change what I have to fit that
<mistym>
For example, ary = []; Find.find('f:\') {|file| ary << file if file =~ /\.txt$/} will give you an array of all .txt files it finds
<mistym>
ridders24: Understand the example code on ruby-doc.org?
<ridders24>
mistym: no it was the example on ruby-doc that threw me.
<mistym>
OK.
<mistym>
The example there is trying to add up the size of every file in your home directory. (aka ENV["HOME"])
RORgasm has joined #ruby-lang
<ridders24>
mistym: Ok
<mistym>
How familiar are you with blocks? Do you know what the `do |path|` part of the code is doing?
<ridders24>
mistym: I am unaware of blocks
<mistym>
OK.
andrewhl has joined #ruby-lang
<mistym>
A block is a section of code which is passed to a method.
<ridders24>
mistym: method being the "define" ?
<mistym>
ridders24: Yes, a method is a function defined with `def; code goes here; end`. Find.find is a method that you call with its name.
<ridders24>
mistym: Ok
<mistym>
For a method that iterates, like Find.find does, the block will be executed once for every iteration - in this case, once for every file or directory it finds.
NinoScript has joined #ruby-lang
<mistym>
Since it's iterating on multiple objects, you need a way to address the objects it's passing to your block! That's that the |variable| is. It's a variable that stands in for each object the method is executing with your block.
<mistym>
So, with Find.find, |path| takes a turn being every file in the directory.
<ridders24>
mistym: ok let me try a simple find.find so I can see it working
<mistym>
For a really simple one, try this: Find.find(put the path to a directory here) {|path| puts path}
<mistym>
ridders24: Oh, right - I forgot to mention.
<mistym>
ridders24: Find comes as a part of the standard Ruby library, but it's not loaded by default.
<mistym>
You can load it by doing require 'find'
Rich_Morin_ has quit [#ruby-lang]
<ridders24>
mistym: ah right, I wondered what the require was for in other ruby doc examples ive seen
zmack has joined #ruby-lang
<ridders24>
mistym: ok so that appears to have produced me a list of files that are in the same dir as the script is
<ridders24>
mistym: do I need to do **/ to look outside of that?
<ridders24>
misytm: ignore that
* mistym
ignores that
<ridders24>
mistym: cool, Im happy I understand how that works
<mistym>
ridders24: Great! :D
<ridders24>
mistym: so many ways of doing the same thing in ruby
<ridders24>
mistym: how do I search for a file extention with that though like i had before?
<mistym>
ridders24: Well, since the block variable is representing your files, you just need to run a check on it. Say, path =~ /\.txt$/, which will return true if it ends with .txt and false otherwise.
<ridders24>
mistym: what does =~ mean?
<mistym>
ridders24: It matches a string against a regular expression, which is a kind of pattern.
<mistym>
So, for instance: 'foo' =~ /\.txt$/ ==> this will fail because 'foo' doesn't match the pattern
<mistym>
'foo.txt' =~ /\.txt$/ ==> this will return true, because 'foo.txt' does match the pattern
`micro has quit [#ruby-lang]
bjensen has joined #ruby-lang
<Mon_Ouie>
=~ is more generically the pattern matching method
<Mon_Ouie>
String#=~ and Regexp#=~ are the most common uses, but you could use it for other forms of pattern matching
<ridders24>
mistym: thank you for explaining that
rorymckinley has joined #ruby-lang
zmack has joined #ruby-lang
fayimora has joined #ruby-lang
paul0 has joined #ruby-lang
<ridders24>
mistym: is this wrong? Find.find("C:/") {|path =~ /\.txt$/| puts path}
<mistym>
ridders24: The part between the pipes is just the definition of the variable. You don't put code there, just define a name.
<ridders24>
mistym: so Find.find("C:/") {|path| puts path =~ /\.txt$/} which im currently running and getting two digit numbers appearing in console
<ridders24>
mistym: why??
<mistym>
ridders24: You're close!
<ridders24>
mistym: hahaha ok ta
<mistym>
What you're doing there is printing the result of matching path =~ /\.txt$/
<mistym>
Instead what you probably want to do is print path *if path matches the pattern*
Clordio has joined #ruby-lang
wallerdev has joined #ruby-lang
<mistym>
(More specifically: `path =~ /\.txt$/` returns the position where the start of that match is. In Ruby, any return value that isn't explicitly "nil" or "false" is considered to be true.)
<ridders24>
sorry you have lost me
<ridders24>
so those numbers were matches?
<mistym>
Basically, yeah. For example:
<mistym>
'foo.txt' - Where does the .txt pattern start? It starts at the third letter. (Counting starts from zero.)
<mistym>
So 'foo.txt' =~ /\.txt$/ returns 3.
<mistym>
If it didn't match the pattern, it would return false.
<mistym>
Since it returned something that *isn't* false, it's considered to be true by things like if statements.
lsegal has joined #ruby-lang
<ridders24>
mistym: ah ok, so it was telling me the start of the pattern on a file that matched.
<mistym>
Exactly!
<ridders24>
mistym: if I use a *if statment does it not require a *or, or *and as well?
<mistym>
ridders24: Only if you have more than one condition.
srbaker has joined #ruby-lang
<mistym>
foo if bar
<mistym>
Theres only one condition, so no need for an `or` or `and`
<ridders24>
mistym: puts path if path =~ /\.txt$/} woot it works. sorry I take so long to grasp this
<mistym>
:D Great!
Swimming_Bird has joined #ruby-lang
<ridders24>
you guys have lots of patients for people like me
<mistym>
It's a well-known fact that rubyists are among the friendliest people on the internet.
<mistym>
I was also a newbie about a year ago, and appreciated all the help I got. Paying it forward, etc.
Axsuul has joined #ruby-lang
Axsuul has joined #ruby-lang
<ridders24>
its a fantastic language for the most part, I've learnt stuff so much quicker than when I did pascal or delfi years ago
judofyr has joined #ruby-lang
Teddy2steper has joined #ruby-lang
sandbags has joined #ruby-lang
<ridders24>
mistym: why is path a undifined var when its in the if statement? http://pastie.org/3745562
<mistym>
ridders24: Line 5?
<ridders24>
mistym: yh
srbaker has joined #ruby-lang
kyrylo has joined #ruby-lang
<judofyr>
ridders24: because path is only defined inside the block
<mistym>
Blocks have their own variable scope. Variables defined inside a block will not continue to exist once the block is over
<mistym>
Another thing to keep in mind - when you pass a block to a method, it will only progress to the next line after it finishes *every iteration* of that block. So your File.open... bit will only be executed once, after the block is finished.
<ridders24>
mistym: yh i noticed that, so it still populates console first. Im not sure what to define path as
jacktrick has joined #ruby-lang
<mistym>
ridders24: So what's your goal here? You want to write a list of the files you find to disk?
FiXato has joined #ruby-lang
<ridders24>
the idea is to provide a speadsheet in .txt form to the script which contain the filename pattern. I then want the script to search the specified drive letter and output into another txt file the files that match the pattern and file extention
<mistym>
OK.
<mistym>
So you're going to have a list of files here that all need to be saved to disk, not just one,
<mistym>
right?
<mistym>
You've got a couple ways you can approach this:
<mistym>
- have the Find.find block write the files to disk as it finds them, one line at a time
<ridders24>
the files are already located on the specified disk. The list contains part of the file names, I need to determine if the files still exist
<mistym>
Right. So your goal here is going to be to build a list of files that exist?
<ridders24>
mistym: exactly :)
MrWGW has joined #ruby-lang
<MrWGW>
hey there, are there any ruby projects similiar to Python's Fabric?
<mistym>
OK, so - I can see two ways to approach this.
<ridders24>
mistym: Ok
<mistym>
- check the files, then write out to your list of files on disk one line at a time as it finds them
<mistym>
- use the Find.find block to build a list of files, then write that list to disk all at once
<yxhuvud>
MrWGW: dunno. What do Fabric do?
<ridders24>
mistym: so I have a little bit of the first part of finding the files, although I need to give it the list containing the partial file names to look for the pattern
<mistym>
ridders24: Right. Let's take this one step at a time - maybe work on logging your list to disk, and then after you can work on the pattern part?
<ridders24>
mistym: sounds good to me
gregmore_ has joined #ruby-lang
eggie5 has joined #ruby-lang
<mistym>
ridders24: What version of Ruby are you using, btw?
<ridders24>
mistym: 1.8.7
<eggie5>
text =~/code/ how can I use the regex but where code is a variable???
<eggie5>
not a literal string
<bougyman>
what?
<bougyman>
yes
<bougyman>
text =~ /#{code}/
<bougyman>
as long as code returns a string.
<eggie5>
bougyman: oh serious… i feel dumb
<bougyman>
if you use vim you'll wanna do text =~ %r{#{code}}
<bougyman>
/#{code}/ can throw vim syntax highlighting off.
<ridders24>
mistym: when I define path as path = Find.find("C:/") {|path| puts path if path =~ /\.txt$/}. In the output file I get nil
esad has joined #ruby-lang
RomyRomy has joined #ruby-lang
RubyRedGirl has joined #ruby-lang
indeterminate has joined #ruby-lang
judofyr_ has joined #ruby-lang
io_syl has joined #ruby-lang
robertcarter has joined #ruby-lang
<MrWGW>
yxhuvud: it manages ssh connections to remote hosts
<MrWGW>
allowing you to do things you would normally need puppet, chef or cfengine for, but in a simpler way
<ridders24>
mistym: I tried this instead http://pastie.org/3745562 to get the output to work. I get no errors. however i get no output either. why?
<shevy>
ridders24 about the structure, I would put all requires on the top of the file. also, you should indent with 2 spaces at "out_file.puts path if path =~ /\.txt$/"
<shevy>
I am not sure if I understand your code anyway or whether you called it correctly or not, but from this code it seems as if you write into a file?
<shevy>
you could do something like "puts path" too, just to see if you have anything in that variable anyway
RubyRedGirl has quit [#ruby-lang]
wallerdev has joined #ruby-lang
RubyRedGirl has joined #ruby-lang
<ridders24>
shevy: I made those changes you suggested. the idea is to write into a file. I just cant seem to get that to work lol
<ridders24>
i can get it to list in console
<ridders24>
just not write into the file
ericlalande has joined #ruby-lang
<shevy>
ok so you want to write something into a file
<ridders24>
yes, "path" is what is want to write into the file
<shevy>
I'd add a check to ensure that to_file is not nil
<shevy>
or if it is nil, assign a default value
<shevy>
to_file = "default value here" if to_file.nil?
IPGlider has joined #ruby-lang
dot3c has joined #ruby-lang
tomzx has joined #ruby-lang
srbaker has joined #ruby-lang
RubyRedGirl has joined #ruby-lang
<nuclearsandwich>
win 24
rolfb has joined #ruby-lang
tomzx has joined #ruby-lang
<mistym>
shevy: What are you doing teaching him to use curly braces for multiline blocks? ;)
<shevy>
it's less characters!
Radium has joined #ruby-lang
savage- has joined #ruby-lang
rolfb has joined #ruby-lang
dot3c has joined #ruby-lang
dot3c has joined #ruby-lang
tomzx has joined #ruby-lang
RomyRomy has joined #ruby-lang
datanoise has joined #ruby-lang
jarred has joined #ruby-lang
<mistym>
ridders24: Sorry I got pulled away. I actually need to head off for awhile, but I'll be back later if you still need any help!
<ridders24>
mistym: hi just got back myself. Thanks for your help so far, I'll look out for you if your back later
tonesfrommars has joined #ruby-lang
esad has joined #ruby-lang
srbaker has joined #ruby-lang
ridders24 has joined #ruby-lang
unc0nnected has joined #ruby-lang
surfprimal has joined #ruby-lang
srbaker has joined #ruby-lang
uniqanomaly has joined #ruby-lang
ryanf has joined #ruby-lang
slaytanic has joined #ruby-lang
Teddy2steper has joined #ruby-lang
francisfish has joined #ruby-lang
RORgasm has joined #ruby-lang
gsav has joined #ruby-lang
retro|cz has joined #ruby-lang
torrohot has joined #ruby-lang
Xzyx987X has joined #ruby-lang
loh has joined #ruby-lang
nif has joined #ruby-lang
fayimora has joined #ruby-lang
fayimora_ has joined #ruby-lang
headius has joined #ruby-lang
rking has joined #ruby-lang
rking has joined #ruby-lang
fayimora has joined #ruby-lang
gorsuch has quit ["ERC Version 5.3 (IRC client for Emacs)"]
Zolrath has joined #ruby-lang
igotnolegs has joined #ruby-lang
RomyRomy has joined #ruby-lang
Clordio has joined #ruby-lang
rking has joined #ruby-lang
rking has joined #ruby-lang
Teddy2steper has joined #ruby-lang
Teddy2steper has joined #ruby-lang
voker57 has joined #ruby-lang
nif has joined #ruby-lang
bjensen has joined #ruby-lang
Teddy2steper has joined #ruby-lang
<dreinull>
is there a better way to check if a String is not nil? and not empty?
<burgestrand>
better than?
<apeiros_>
a string is never nil
<apeiros_>
if it is nil, it's not a string
<apeiros_>
</pedantic>
<dreinull>
apeiros_: :)
<apeiros_>
!(v.nil? || v.empty?)
<apeiros_>
!v.blank? if you use rails
<apeiros_>
oh, or: v.present?
<dreinull>
apeiros_: yup, that's what I'm doing, but not rails.
<apeiros_>
or: v && !v.empty?
<dreinull>
apeiros_: I'm aware of the nil and empty variations. Thought maybe I have missed a simpler way of checking them in one go
<dreinull>
Thank you!
NinoScript has joined #ruby-lang
<apeiros_>
not in vanilla ruby, no
NinoScript has joined #ruby-lang
seanstickle has joined #ruby-lang
<dreinull>
nil and empty is annoying when you deal with forms and you never know what's coming in.
surfprimal has joined #ruby-lang
<apeiros_>
dreinull: first rule about dealing with input: normalize your data
<apeiros_>
sadly, the biggest and most known web framework in ruby fails utterly at that
<matled>
why does ruby allow "-5\n.abs" but not "-5\n#comment\n.abs"?
JackNorris has joined #ruby-lang
<apeiros_>
matled: probably because the parser is already rather complex and they didn't consider each and every edge-case?
<dreinull>
apeiros_: what do you mean by normalize? Encodings? Availability of data?
<canton7>
-5.\n#comment\nabs works
<matled>
apeiros_: you think this is worth a bug report??
<matled>
s/\?\?/?/
<matled>
canton7: yep, so does "-5 \\\n#comment#.abs"
mikeric has joined #ruby-lang
<apeiros_>
dreinull: e.g. make sure you accept only one type, and in the normalization step you convert all acceptable values to that type. the old saying of "be broad in what you accept" is IMO stupid btw., it's a good idea to limit what you accept to the necessary.
<matled>
canton7: it's just that I was told about the feature to put the dot in the next line which I find quite nice for long method call chains. now I start to use it and it breaks as soon as I put comments in between..
<apeiros_>
matled: it's nothing I'd file a bug report over it. but sure, why not. it looks like an omission to me.
<dreinull>
apeiros_: sure, in this case I accept pretty much everything and just escape if it's bad. But since you can leave some fields empty I have to deal with stupid edge cases where there is no data coming.
postmodern has joined #ruby-lang
thone has joined #ruby-lang
<dreinull>
the client server bridge is so boring.
<apeiros_>
dreinull: "filling holes" is one step in normalization
<apeiros_>
aka defaultize
<dreinull>
apeiros_: I'm working on a small dictionary app. There are no defaults :)
<apeiros_>
dreinull: if it is valid to omit a value - sure
<apeiros_>
obviously you somehow deal with it :)
<dreinull>
hey man, why do so many of your entries have bar as translation?
<apeiros_>
:D
<shevy>
bar?
<dreinull>
foo = bar
<apeiros_>
"that's cuz it's an AWESOME word, you insensitive clod!"
<dreinull>
ah, slashdot reader
<dreinull>
I feel old for being a slashdor teader
<apeiros_>
it's not what it used to be.
<dreinull>
wow, this typo doesn't happen often
<dreinull>
I'm fine with it.
<dreinull>
slow news for old nerds
<apeiros_>
I still read it. its comment system is still great. but yeah, it's not the prime news source.
mikeric has joined #ruby-lang
<dreinull>
yup the comments is what makes it great. no need to rtfa
mistym has joined #ruby-lang
<shevy>
read the fucking ... a .. ? a what is a
<dreinull>
article, shevy!
<apeiros_>
dreinull: often I don't even rtfs :)
<shevy>
ah
<apeiros_>
it's often wrong/misleading anyway
<dreinull>
it's for the entertainment anyway.
<dreinull>
otherwise you shouldn't rtfi
<dreinull>
where i is internet and not just irc :)
<shevy>
hmm
<shevy>
I have a sudden violent feeling with those shortcuts
<dreinull>
shevy: how so?
<shevy>
I dont know them!
<dreinull>
hm
<dreinull>
things could be worse
RORgasm has joined #ruby-lang
PsiliPharm has joined #ruby-lang
derpmcherp has joined #ruby-lang
derpmcherp has quit ["Leaving"]
ericmuyser has joined #ruby-lang
hagabaka has joined #ruby-lang
hagabaka has joined #ruby-lang
petercooper has joined #ruby-lang
unc0nnected has joined #ruby-lang
nif has joined #ruby-lang
adhominem has joined #ruby-lang
Sailias has joined #ruby-lang
<adhominem>
with TCPServer.accept I can get new sessions, test their IP, and then possibly close them
<adhominem>
I am looking for a way in Ruby to not accept sessions from a random IP, like 155.155.155.155, in the first place
adhominem was kicked from #ruby-lang by apeiros_ [don't cross-post]
adhominem has joined #ruby-lang
<adhominem>
I'm unaware of the relationship between #ruby and #ruby-lang ....
<apeiros_>
you don't get it, hm?
<adhominem>
No I'm just unaware of it ..
<apeiros_>
only assholes let people work without letting them know that other people work on the same thing.
<adhominem>
Yeah no one is like "hey bro I'm about to spend an hour researching this .. let me know if you ask anyone else in the universe about it"
<ryanf>
yeah what? usually if something doesn't get answered within 5 minutes it's time to try asking somewhere else
<ryanf>
that seems like a really weird overreaction
<apeiros_>
ryanf: then either leave where you didn't get an answer or state that you're carrying it over to the next place
<apeiros_>
otherwise you're just being an ass
<adhominem>
my bad bro .. fyi you were being a dick :)
adhominem was kicked from #ruby-lang by apeiros_ [fuck off]
<ryanf>
I really don't see how. you picture a scenario where someone in #ruby has silently gone off to spend 10 minutes working on it?
<ryanf>
without saying anything?
<apeiros_>
ryanf: the point is that somebody in #ruby will not see that somebody in #ruby-lang already answered
bjensen has joined #ruby-lang
<apeiros_>
so it may be 10min later that he sees the question, takes his time and tries to answer
<ryanf>
surely the point where that becomes an issue is if someone in #ruby-lang answers and then he doesn't tell #ruby that it's resolved?
<apeiros_>
so yes, rude waste of other peoples time.
<ryanf>
otherwise you might as well say it's rude to ask an IRC room instead of asking one person at a time, because maybe two people will think about it at the same time
<apeiros_>
ryanf: IME somebody who doesn't say it upfront won't say it after the fact either
<apeiros_>
ryanf: no, that's not the same. it'd be rude to ask everybody in a privmsg. that'd be the equivalent.
<apeiros_>
in the room, you can see whether an answer was given.
<apeiros_>
end of topic.
<whitequark>
someone clearly has op rights for the wrong reason.
<apeiros_>
oh my, do we have ass-hat-behavior defenders day or something?
<apeiros_>
but reminds me…
<whitequark>
... said a man who surely doesn't behave like an ass
esad has joined #ruby-lang
<apeiros_>
careful with insults whitequark
<whitequark>
like kicking someone with "fuck off" message and then banning is not behaving like an ass
<apeiros_>
whitequark: if you want to discuss it, pm me. if you're just in for the show, stop it.