DevHeads.net

Postings by Andreas S.

new: a problem with type method not being undefined

I am using ruby 2.0.0p195. I am, however, starting to think that
type-method is not defined for this version of ruby. I ran the below
expressions and I got values for the first two expressions but due to
the error caused by type-method I did not get values for the expressions
after the fourth expression.

Regular expression to find a break in a pattern

I have a large file which lots of gibberish in and I'm trying to find
the meaningful sections.

Essentially I'll have something like this:

random data lines

random data lines

random data lines

random data lines

What I need to do is locate the line(s) where From is different from To.
In this case, the one From "1313132" To "1313133".

I don't know how to do this kind of match, but I assume that Ruby has a
way?

RestClient failing to GET resource using SSL client certificate

Hi All,

I'm trying to use RestClient to retrieve a page that's secured using an
SSL client certificate.

Parsing info from url

Is there is a way to get page as text (like curl in php) and parse it to
get needed info?
Also, I don't really know, is there is a way when getting url through
something like curl to enter user data in forms or activate javascript
on page (if there is authentication before showing page etc)?

newbie question on using system syntax versus backticks

I keep running into this, and change my approach if undesirable effects
are encountered. But what I'd like to systematically understand is the
difference between issuing a system command such as:

system( "some_system_command" )

and simply doing it with backticks:

`some_system_command`

What is the difference, and is there an approach that is preferable in
terms of "good Ruby programming"??

Rename multiple files

Hi,

Could anyone help me in writing a code which could replace file names
letters to lowercase and spaces to dashes? For example:

Ruby Forum to ruby-forum

Thanks.

Installation problem for SciTE editor

I have installed Ruby 2.0 while I still have Ruby 1.8.7 in my system.
Now when I run my ruby program in SciTE editor it is still executed by
Ruby 1.8.7 interpreter, How do i change the control of 2.0 Interpreter
in SciTE editor?

RAJ

new, with an idea, and not sure what to learn next

Hi. I've been going through the CodeAcademy courses for Ruby over the
past few weeks, and I spent a couple months last year learning Python
and writing a couple of card game programs. This is my only experience
with programming at all and, despite feeling I have an OK grasp on the
Ruby language, in theory at least, I'm still floundering for where to go
or what to do for practice.

I've been thinking lately that I want to design a program, specifically
for me, that keeps track of my finances.

output file from clipboard in unix

Hi all,

I'm new to Ruby and pretty new to programming in general. My limited
prior experience is with JavaScript, so I'm not accustomed to handling
file I/O or working with Unix/Terminal. I'm working on a script that
takes a large quantity of text copied from a web browser and does some
reformatting so the result lines up neatly in a CSV and eventually a
spreadsheet. Basically, I'm using a few regex/gsub statements to remove
unnecessary text from the beginning of the page and to add/remove tabs
from certain places. I've got two issues with this script, please see
the attached files.

1.

Ruby Programming Practice

Hey guys have been learning the basics of ruby and practicing some
simple ruby scripts. However i am looking for practice programming
questions/papers/material to test my knowledge and so that i can get
some good practice in ruby programming so that i am confident about my
basics.

Please could you'll provide some links to sites or certain books which
have topic wise questions in ruby(for ruby scripting).

Thanks a lot for all the help...

why first 16 bytes are wrong with ruby openssl aes 128 cbc ?

I use openssl in ruby and openssl in bash, but the first 16 bytes with
ruby/openssl are wrong, why ?

Need help to understand the Enumerable methods

I am very eager to know about the Enum#sort{|a,b|..}

<a href="http://www.ruby-doc.org/core-2.0/Enumerable.html#method-i-sort" title="http://www.ruby-doc.org/core-2.0/Enumerable.html#method-i-sort">http://www.ruby-doc.org/core-2.0/Enumerable.html#method-i-sort</a>

Now my question is about the internal mechanism.

***Returns an array containing the items in enum sorted, either
according to their own <=> method, or by using the results of the
supplied block.

Ruby 'gets' truncates input to 256 characters (Windows)

Is this a 'feature' of Ruby on windows?
I am trying to enter a long string (> 256 characters but generally <
512) in Ruby with:

puts "Enter long string"
ilogo = gets.chomp
puts ilogo

For some reason, it always truncates the input to keep only 256
characters (before chomp).
I verified that Ruby accepts longer strings, and that Windows 7 command
line console also accepts strings > 256 chars. I have seen that people
don't have the issue with MacOS, but others do have it with Windows XP.
I am running Win7.

how to create a method object of from an singleton method?

class Foo
def suprim;end
end

p foo = Foo.new #=> #<Foo:0x90bd908>
p foo.method(:suprim) #=> #<Method: Foo#suprim>
p Bar=foo.singleton_class #=> #<Class:#<Foo:0x90bd908>>
p foo.define_singleton_method(:hello) { "#{self}: Hello there!" } #=>
#<Proc:0x90bd2a0@/home/kirti/ruby/test.rb:8 (lambda)>
p Bar.method(:hello) #=> `method': undefined method `hello' for class
`Class' (NameError)

My question is how to create a method object of an singleton method,like
I did `foo.method(:suprim)`?

configure option for doxygen

So I'm building some Ruby releases I don't want it to build any docs
for.

When running configure, I already add --disable-install-doc.

However, since I have doxygen, configure notices that and adds it to be
built. I normally just quick edit the resulting Makefile and remove
doxygen.

However, is there a way to tell configure to --disable-doxygen or
something similar?

Error in Migration

I am a RoR newbie. I am getting this error when trying to migrate my 2.x
project to 3.x project.
actionpack-3.2.13/lib/action_dispatch/routing/mapper.rb:109:in
`normalize_path': undefined method `to_sym' for nil:NilClass
(NoMethodError)

In that line i can see the following code
options[$1.to_sym]||=/.+/?

why $1.to_sym ends with NilClass error

Could you give me some Website for Learning Ruby

I'm learning Ruby and I search some Website for learning Ruby
but I want have some Website same as Tutorial with more information
about variable,class,extend... (very detail).
Who can help me this problem? Thanks...

Configure/Integration of MYSQL in Tomcat using Ruby script

Hi,

I have installed MySQL with the help of MySQL msi package through
command prompt and now trying to do configuration of MySQL in Tomcat
help of Ruby recipes. I have downloaded Mysql and Tomcat recipes from
Opscode Cookbook. But I am not getting how to do Configuration of MySQL
in Tomcat help of Ruby. Can any one please help me on this how to
proceed.

Thanks.

n00b looking to learn from the best

Hey Rubyians!

I am not used to joining online forum's and I am eager to join the Ruby
community. This is the first language I am learning and have a practice
problem that I cannot seem to get. Can you enlighten me? I'm looking
forward to learning from all of you!

Here is the question:

Write a method named lassy_sum(numbers) that takes an array of numbers.
lassy_sum should multiply each number in the array by its position in
the array, and return the sum.

I don't quite understand how to multiply each number in the array by its
position in the array. Any help will be greatly appreciated!

converting a dns msg to wireformat -- dnsruby

I'm trying to convert a dnsruby message to wire format. Is there any way
to do that?
Much like toWire() in dnsjava ??

Thanks.

Help with time

If i have a date time like this "2013-04-01T12:01:03-07:00"

how can i get a Time object in Ruby 2 without UTC added. i mean get
"2013-04-01 12:01:03"

defined?() confussion

Hi guys. Can you tell me why does this happen?

if 1.==(2)
c = 3
else
b = 5
end

defined?(c)
#=> "local-variable"

I was expecting nil, because the thread doesn't pass trough the second
line, 1 is not equal to 2. Seems that Ruby gives the value nil to c, so
Ruby creates the object in RAM, will be garbage collected after, of
course. Why does this happen? it is not a waste of resources?

Monkey patch Exception class

What I want to achieve is, is that I can hook into the Exception class
of Ruby so that I can trigger special logging events, when an exception
occurs.

I could easily define custom error classes, but I would like to take a
more general approach.

Does someone have advice on how to do this?

Thanks!

Slow reading output from Open3.popen3??

I've never tried using this function before, but I am now using as part
of a code compilation build script (using 'make' on UNIX).

It looks something like this:

==================================

stdin, stdout, stderr = Open3.popen3( 'make codename' )
stdin.close

puts "Reading STDOUT"
outfile.puts stdout.read
stdout.close

==================================

I'm trying to get the output from the 'make' command (which is quite
large), so I can dump it to a file for later diagnostics.

However, when it gets to the stdout.read, it seems to hang (or at least
take so long I've never seen it fin

Need help for Kernel methods

<a href="http://www.ruby-doc.org/core-2.0/Kernel.html#method-i-__dir__" title="http://www.ruby-doc.org/core-2.0/Kernel.html#method-i-__dir__">http://www.ruby-doc.org/core-2.0/Kernel.html#method-i-__dir__</a>

Kernel#_dir_ :- *Returns the canonicalized absolute path of the
directory of the file from which this method is called. It means
symlinks in the path is resolved.*

Can anyone tell me what the line means in **?

Thanks

Help whit returning

Hey i dont know how to return line nr 69-71 to 81-82
can i get some help here?

def death()
puts "MOHAHAHAHAH."
Process.exit(1)
end

def cave()
blk = Proc.new {return}
blk.call
end

puts "The Game"

puts "Chose yourself a name"
name = gets.chomp

puts "Welcome #{name} now you'r journey will start good luck"

puts "You are in the jungel and trying to get out of there."
puts "You are walking and walking.........................."
puts "Trying to find somthinge that can help yourself......"
puts "What is that thing over there?"
puts "Oh no a hell of a big snake!"
puts "What will you d

How to create a countdown timer with Ruby

If you scroll down on <a href="http://danieltosh.com/" title="http://danieltosh.com/">http://danieltosh.com/</a> you will see a countdown
timer, I'd like to know how to create one of these with Ruby, which will
be implemented onto my Rails application.

I've searched various sources to no avail, with that said - any
suggestions on how to create this sort of thing would be great!

thanks.

callback limitations with `inherited`

class C
def self.inherited(subclass)
puts "#{self} just got subclassed by #{subclass}."
end
end
class D < C
end

The limits of the inherited callback:

*Everything has its limits, including the inherited callback. When D
inherits from C, C is D’s superclass; but in addition, C’s singleton
class is the superclass of D’s singleton class. That’s how D manages to
be able to call C’s class methods. But no callback is triggered. Even if
you define inherited in C’s singleton class, it’s never called.*

can anyone help me what the lines above inside ** means?

Basic question about blocks

Hello forum,

I am new to Ruby and have a question about blocks.

A) Below is the code I have put in a file <blocksexample.rb>:

animals { |x| puts "Hello, #{x}" }
animals { |x| puts "It's #{x.length} characters long!" }
B) I run the <blocksexample.rb> as below....only once:
C) The output is a

Unexpected output from Array#<< method.

I was writing a code,and doing so I got some unexpected result. Can
anyone point me by saying where I did wrong?

irb(main):001:0> a=["a","b","c"]
=> ["a", "b", "c"]
irb(main):002:0> a[-1].concat("j")
=> "cj"
irb(main):003:0> a<<a[-1].concat("j")
=> ["a", "b", "cjj", "cjj"]

My expected output is: ["a", "b", "c", "cjj"]

Thanks