Feb 142012
 


<graft> nah i need something more general
<denom> Do people use sandbox to manage dependencies, or perhaps install a new ruby with RVM ?
<denom> ..for a specific project
<swarley> denom, you can use rvm to get different versions and then specify the ruby version to use for a specific project
<denom> So I could have multiple installs of 1.9.3, each for a different project.
<denom> I’m trying to keep my gems cleanly seperated between projects. sandbox is a little wierd because it moves $HOME or something
<luxurymode> Can anyone recommend a good library for interacting with AWS?
<rippa> swarley: string.dump
<swarley> denom, how so? gems all go in one dir and then they are only brought in as needed
<swarley> you shouldnt need to manage installed gems
<swarley> on a per project basis
<swarley> rippa, ah, i should have started with rdoc
<denom> what about differing gem version requirements? Is this not a problem?
<swarley> well, in your gems dir
<swarley> there are multiple folders
<swarley> 1.8/ 1.9/
<swarley> so most of the time, if the gem supports your version there will be no problem
<denom> ahh right, lets assume we only have 1.9 installed (I see RVM will only let me install one instance of that)
<swarley> if it works with 1.8 it should work with 1.9
<denom> well, I guess I’d real more comfortable with a clean way to isolate environments
<denom> s/real/feel/
<swarley> well, you can always build locally and use it out of the install dir
<swarley> but other than that its better to just use the same env
<denom> ahh: rvm install 1.9.3 -n “my-dev-env”
<luxurymode> how do i get the direct parent folder of a file, e.g the lowest folder in the path?
<luxurymode> *sorry if i didnt express that very clearly
<swarley> luxurymode, you mean
<swarley> you have file a
<swarley> and you want ../
<swarley> ?
<luxurymode> i have path/to/some/file and i want “some”
<swarley> ad
<swarley> ah*
<swarley> well
<swarley> File.expand_path(File.dir(__FILE__)).split(‘/’)[-2]
<swarley> that should work
<swarley> but im sure there is a better way
<swarley> let me check
<luxurymode> File.dir…?
<GSpotAssassin> Is there something that will parse Ruby and spit out Javascript?
<swarley> luxurymode, the other way to do it would be
<swarley> dir = Dir.chdir(‘.’)
<swarley> i think
<swarley> no
<swarley> luxurymode, the example with File.dir is assuming you want the path to the file that is being worked with
<luxurymode> swarley, no all i have is a file
<swarley> are you talking about having the file path?
<luxurymode> passed into as an arg to some script..
<swarley> okay so
<swarley> you’ll want to expand the directory
<swarley> File.expand_path(File.dir(your_file))
<swarley> that makes
<swarley> /usr/home/swarley/Documents/file.test
<swarley> it may leave off the file
<swarley> let me check
<luxurymode> undefined method `dir’ for File:Class (NoMethodError)
<swarley> ah my mistake
<swarley> irb(main):006:0> File.expand_path(File.dirname(__FILE__))
<swarley> => “/home/swarley/Documents/Programming”
<luxurymode> but i dont want the full pathim not trying to create a filepath
<swarley> and then you can split that string by / and get the last element
<luxurymode> i want the last subdirectory in a file’s path
<swarley> yes
<luxurymode> ah ok
<swarley> irb(main):008:0> File.expand_path(File.dirname(__FILE__)).split(‘/’).last
<swarley> => “Programming”
<luxurymode> sweet
<luxurymode> swarley thanks a lot
<luxurymode> appreciate it
<swarley> yeah, of course
<MaskRay> how big is a complete rubygems mirror? my local mirror has gain 19G now and doesn’t seem to terminate in the foreseeable future..
<vandemar> rubygems says 33,945 gems since 2009, hypothetically at 1M per gem, that’s 33G.
<vandemar> Does a mirror include old versions of gems? If so they could be smaller and still take >33G space
<MaskRay> what’s the preferred mirroring tool? i’m now using https://github.com/rubygems/rubygems-mirror
<Jagan_> hi friends,
<Boohbah> hi Jagan_
<Jagan_> I need help for database. I will created one application in sqlite3 database, but now i changed the database for mysql. Anyone help me..
<Jagan_> Hi Boohbah :)
<Jagan_> Please any one help me…
<Jagan_> Boohbah_
<gokul> Jagan_, http://guides.rubyonrails.org/getting_started.html seems to explain about that
<Boohbah> there is also #rails and #rubyonrails if you are using rails
<Boohbah> i don’t know much about rails, sorry
<gokul> ohh there is #rails
<Jagan_> okay thank you gokul and Boohbah
<Jagan_> Now i try to change the database. but functionality wise some issues in mysql gokul..
<banistergalaxy> Jagan_: join #rails
<banistergalaxy> Jagan_: we dont generally answer those questions here
<Jagan_> banistergalaxy_ okay thank you..
<kp666> .
<hh__> is it possible to run a shell command with rake?
<banistergalaxy> hh__: sh “ls”
<hh__> thanks
<shevy> hmmm
<shevy> when you have a class like Foobar; def initialize; @some_value = 5; where @some_value can change… how do you store this into a file? I mean the whole class, ideally…
<shevy> including the current @some_value
<banistergalaxy> shevy: did u like my answer for u on ruby-forum
<shevy> what answer
<banistergalaxy> shevy: i try my best 4 u, and get no reply, u hurt my feelings
<shevy> I only looked at the _
<banistergalaxy> shevy: http://www.ruby-forum.com/topic/3585350
<banistergalaxy> hehehe
<shevy> ewww missing_method magic :(
<banistergalaxy> that’s not method_missing puppy
<banistergalaxy> pry commands arne’t ruby at all ;)
<banistergalaxy> it’s not even ruby
<banistergalaxy> hehe
<shevy> but candlerb!
<banistergalaxy> oh
<banistergalaxy> ya
<shevy> well ok
<shevy> let’s see
<shevy> waaaah
<shevy> Error loading /.pryrc: undefined method `block_command’ for #
<hh__> banistergalaxy: there’s no way to set a shell env variable in rake?
<shevy> Pry version 0.9.7.4 on Ruby 1.8.7
<banistergalaxy> hh__: i never said there wasn’t
<banistergalaxy> shevy: update pry
<shevy> hehe kk
<banistergalaxy> shevy: we’re at 0.9.8.1
<lolmaus> Hi!
<hh__> banistergalaxy: how would i do that?
<shevy> Successfully installed pry-0.9.8.1
<banistergalaxy> hh__: by asking me, i guess
<hh__> sh “SOME_ENV=testing command” doesn’t seem to work
<banistergalaxy> hh__: ENV['SOME_ENV']
<lolmaus> I’m doing `p ARGV.first` inside wtf.rb with either `ruby wtf.rb “one two”` or `ruby wtf.rb one two`. In either way, it returns “one”. How do i pass a single argument with spaces?
<banistergalaxy> lolmaus: quote it and use shell words
<banistergalaxy> “hello baby”
<lolmaus> banistergalaxy, i’m doing this: ruby wtf.rb “hello baby”
<lolmaus> banistergalaxy, it would return `hello`
<shevy> I am beginning to actually like gems
<fourcolors> gems are nice
<shevy> gem install –ignore-dependencies foobar-1.0.gem
<shevy> greet banister
<shevy> hello banister!
<shevy> hmm now I only have to understand it …
<hh__> if i had a rake task like server:start and server:stop that would start and stop redis, mysql server, etc. is there a more ruby way to do this? instead of using shell commands to start the process and write the <Gekz> so
<banistergalaxy> hh__: you didnt say thanks when i helped you before which makes me think you’re a greedy pig, so i dont want to help you anymore
<Gekz> I’m trying to find a point in an iterator
<hh__> i said thanks the first time
<Gekz> so I can start iterating from that part
<hh__> it’s implied every other time after
<shevy> Gekz!
<shevy> why do I remember the name
<Gekz> can I pass the .each object to another method and return it after nexting for a while
<shevy> you didn’t play warcraft 3 did you?
<lolmaus> banistergalaxy, how do i make it return “hello baby”, not “hello”?
<Gekz> no, I argued with you about YAML APIs.
<shevy> ah ok
<Gekz> like 2 days ago.
<shevy> yeah
<fourcolors> i played once apon a time… i prefer starcraft however
<banistergalaxy> lolmaus: it works for me
<ryanf> yeah me too
<ryanf> ~ ∴ ruby -e ‘puts ARGV.first.inspect’ — “hello baby”
<ryanf> “hello baby”
<shevy> Gekz I think you can do that somehow. Not quite sure how … array = %w( cat dog chick ); x = array.each; x.class # => Enumerable::Enumerator
<lolmaus> What am i doing wrong? :(
<shevy> x.next # => “cat”; x.next # => “dog”
<shevy> lolmaus cool nick you have :)
<ryanf> yeah Gekz you can use .next and .peek on an enumerator object
<shevy> haha there is a .peek method? cool
<ryanf> i think then you’re stuck in external iteration instead of internal though, so you need to keep calling .next once you’ve gotten to the right point
<ryanf> I guess maybe there’s a way around that
<moshef> any cool way to ask if num is negative besides doing < 0 ?
<ryanf> alternately Gekz depending on your use case you may be able to use drop_while
<ryanf> my_enumerable.drop_while { |o| condition_not_met(o) }.each { |o| do_stuff(o) }
<lolmaus> banistergalaxy, ryanf, try this string: “`/mnt/storage/test/RubyMine 3.2.4“`
<ryanf> what’s with all the backquotes
<Gekz> what is drop_white ryanf?
<lolmaus> banistergalaxy, ryanf, it only works if i do BOTH quotes and backslashing: ruby wtf.rb “/mnt/storage/test/RubyMine 3.2.4″
<ryanf> Gekz: http://ruby-doc.org/core-1.9.3/Enumerable.html#method-i-drop_while
<lolmaus> ryanf, ignore the backquotes
<moshef> any cool way to ask if num is negative besides asking num < 0 ?
<lolmaus> Ah! Same thing with “hello baby”
<shevy> moshef hmmmm
<shevy> x = -10; puts ‘X must be negative.’ if x + x.abs == 0
<lolmaus> AH! It’s correct for `ruby wtf.rb “hello baby”`, but splits for `rvmsudo ruby wtf.rb “hello baby”`
<lolmaus> I seem to get it
<lolmaus> It’s linux stuff, not ruby
<shevy> bad bad linux
<shevy> use rubyOS
<MaskRay> nonpositive?
<fabiob> How can you do this in a rubyesque way?
<fabiob> http://pastie.org/3340016
<fabiob> (Getting a symbolic representation of a constant in a generic way, having its value)
<aces23up> anyone know of a string function or gem that converts the string “four” => 4, “five” => 5 just wondering if there is already something before i roll my own.
<Tasser> aces23up, probably chronic does something like that
<shevy> fabiob, where do you set @state ?
<shevy> if you need to do special operations, I’d advice against using attr_accessor
<shevy> and instead, use your own = method
<fabiob> shevy: f.state = Foo::BAR
<fabiob> shevy: it was just an example
<fabiob> shevy: my problem is to get its symbolic representation
<shevy> well BAR resides within Foo
<shevy> but it is not a symbol, it is a constant
<shevy> _ = Object.const_get “Foobar”‘
<shevy> _ = Object.const_get “BAR”
<fabiob> shevy: Maybe “symbolic” is not the right word for it
<shevy> still, your class is kinda bad. f.state = ‘bar’ would seem nicer to me
<fabiob> I would like the output to be “state: Foo::BAR”, as a string
<fabiob> BAR and BAZ are magic numbers
<shevy> when Foo::BAR is resolved, I think it is the value 0×01 already
<shevy> a Fixnum
<shevy> consider like you use:
<shevy> f.state = 5
<shevy> ruby wouldn’t know from where the 5 came
<shevy> Anyway, within “state: #{@state}” you could easily do something like self.class.to_s + ‘::’
<shevy> Hmm idea
<shevy> rather than use:
<shevy> f.state = Foo::BAR
<shevy> use:
<shevy> f.state = ‘Foo::BAR’
<shevy> and make a
<shevy> def state=(i)
<shevy> method on your own, without using attr_accessor
<shevy> and inside that method, you analyze the given input
<shevy> then you can be in full control of what happens
<fabiob> shevy: Yeah, I was thinking ruby has something as get_constant_with_value( 2 ) -> “Foo::BAR”
<fabiob> shevy: mmm, that’s dirty
<fabiob> The alternative is a case statement, but I was hoping in a little Ruby magic :)
<shevy> what should ruby do for you?
<shevy> “state: Foo::BAR” or “state: BAR” <-- you dont describe how to handle the difference
<fabiob> shevy: either one is good, I don’t care
<shevy> aha
<shevy> that’s a lot easier then
<shevy> btw
<shevy> your current code is not valid
<shevy> frobify( @state )
<shevy> def frobify
<shevy> accepts no argument right now
<shevy> fabiob, http://pastie.org/3340113
<fabiob> shevy: Right, it was just an example
<shevy> but as said, it has no way to discern between the 1 and 2
<shevy> oops
<shevy> made a mistake
<shevy> should output 0×01 and 0×02 of course
<shevy> hmmmmmm curious
<fabiob> That’s not what I want
<fabiob> The output should be the _string_ “Foo::BAR”
<shevy> yeah but
<fabiob> (or “BAR”)
<shevy> how should ruby know that this is BAR?
<shevy> remember you do this:
<shevy> f.state = Foo::BAR
<shevy> this gets resolved to the value of Foo::BAR
<fabiob> Ruby should know all the constants of that class, right?
<shevy> sure. class.constants has an Array
<lolmaus> I’ve got a string and a regular expression. I would like to remove the matching part from the string. How do i do that?
<fabiob> And maybe it has a method that gives you a constant given its value
<shevy> http://pastie.org/3340124
<shevy> I think you have to handle that on your own then, I dont think there is an inbuilt method that queries a constant. But it is available for you in the array self.class.constants
<shevy> lolmaus probably something like your_string[start_position, end_position] = ”
<shevy> the regex should return a positional number
<shevy> hmm
<shevy> or perhaps there is a more elegant way
<lolmaus> shevy, it’s simply str.rename(regex,”)
<shevy> x = “foobar”;x[/ob/] = ”; x # => “foar”
<shevy> x = “foobar”; x[regex] = ”; x # => “foar”
<shevy> well, rename looks like gsub actually
<shevy> “foobar”.gsub(/ob/,”) # => “foar”
<shevy> or .sub
<fabiob> shevy: Does this make you scream in horror? http://pastebin.me/73e46fd9037db8e153a33c44e113e2d3
<fabiob> It’s also O(n)
<Tasser> fabiob, do you need constants?
<Amirh> Have you ever thought the degree that a code looks like it’s output?
<shevy> Amirh is there any real correlation?
<shevy> it seems that little pieces of code can generate a lot of different output
<Amirh> shevy, it’s an artistic view about coding.
<Amirh> it’s not a standard.
<shevy> aha
<Amirh> do you code in a way to convey visual information?
<shevy> I try to have every output visually please me
<shevy> sure
<shevy> it makes it easier to spot errors
<shevy> and find tokens of interest
<Amirh> so what are it’s criterias?
<Amirh> how can one code like this?
<shevy> hmm by following certain patterns and conventions
<shevy> it’s a bit hard to say because this is not something that is static
<shevy> it can change with experience
<Amirh> shevy, don’t you want to do a research about it?
<shevy> Amirh nah. it does not strike me as very important. To me it is much more important to increase my productive code output
<Amirh> but it can readability for your future reuse.
<Amirh> can help*
<shevy> I am not sure what you mean. I can understand my own code pretty well. :)
<Amirh> do you code alone or in a team?
<shevy> I am not entirely sure what you are getting to man
<shevy> You turned a general discussion into targeted questioning.
<Amirh> it’s still general.
<shevy> Good. Then I shall leave the discussion to others here.
<Amirh> How can we write codes which convey visual information about it’s output.
<Amirh> shevy, thank you anyway
<Tasser> can I use metaprogramming to define rake tasks?