DevHeads.net

Postings by Ralph Shnelvar

test_super_does_not_work_cross_method

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

Hash documentation

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

How do I get open-uri to deliver the same html as what Firefox is seeing?

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

Nokogiri parsing Google page. Want links

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

Nokogiri html xpath gestalt

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

Question about array of hashes

I'm looking at Page 39 of Why's (poignant) Guide to Ruby ( <a href="http://www.rubyinside.com/media/poignant-guide.pdf" title="http://www.rubyinside.com/media/poignant-guide.pdf">http://www.rubyinside.com/media/poignant-guide.pdf</a> ) and I see

[:shape => 'sock', :fabric => 'cashmere'] +
[:shape => 'mouse', :fabric => 'calico'] +
[:shape => 'eggroll', :fabric => 'chenille']

The result of this is (irb 1.9.2)

irb(main):001:0> kitty_toys =
irb(main):002:0* [:shape => 'sock', :fabric => 'cashmere'] +
irb(main):003:0* [:shape => 'mouse', :fabric => 'calico'] +
irb(main):004:0* [:shape => 'eggroll', :fabric => 'chenille']
=> [{:shape=>"sock", :fabric=>"cashmere"}, {:shape=>"mouse", :fabric=>"calico"}, {:shape=>"eggr

Operator overloading of the subscript operator

I understand that operators (e.g. +, -, *, []) are nothing more than method names so that

irb(main):027:0> x=[101,102,103,104,105]
=> [101, 102, 103, 104, 105]
irb(main):028:0> x.[](3)
=> 104

(Those familiar with operator overloading can skip the example and go to my question below.

Compiling the Ruby 1.9.3 interpreter on Windows 7

Is there a step by step article on what tools would be needed to compile the Ruby interpreter? That is, where to find the latest Ruby code on Github, the compiler to use, compiler settings,
environment variables, etc.

Ralph Shnelvar

Range documentation as changed

In <a href="http://ruby-doc.org/core-1.8.7/Range.html" title="http://ruby-doc.org/core-1.8.7/Range.html">http://ruby-doc.org/core-1.8.7/Range.html</a> it says:
Ranges can be constructed using objects of any type, as long as the objects can be compared using their <=> operator and they support the succ method to return the next object in sequence.

In <a href="http://ruby-doc.org/core-1.9.3/Range.html" title="http://ruby-doc.org/core-1.9.3/Range.html">http://ruby-doc.org/core-1.9.3/Range.html</a> the above statement seems to have disappeared. Has the semantics changed?

Ralph Shnelvar

for enumerators: last, prev ?

I see that enumerators have the methods rewind and next.

Are there equivalent methods "end" and "prev"?

I see reverse_each ... but what if I do have a large enumerable object and don't want the intermediate array created?

The documentation ( <a href="http://ruby-doc.org/core-1.9.3/Enumerable.html#method-i-reverse_each" title="http://ruby-doc.org/core-1.9.3/Enumerable.html#method-i-reverse_each">http://ruby-doc.org/core-1.9.3/Enumerable.html#method-i-reverse_each</a> ) for reverse each says:

- - -

reverse_each(*args) {|item| block } ? enum click to toggle source
reverse_each(*args) ? an_enumerator

Builds a temporary array and traverses that array in reverse order.

If no block is given, an enumerator is returned instead.

- - -

Proc.new v. lambda

Is there a way to programmatically determine if an object was generated by Proc.new versus lambda?

http://ruby-doc.org/docs/keywords/1.9/ : (Object)

What is the purpose of
(Object)
next to every keyword in <a href="http://ruby-doc.org/docs/keywords/1.9/" title="http://ruby-doc.org/docs/keywords/1.9/">http://ruby-doc.org/docs/keywords/1.9/</a>
?

Trivia question: What is the only keyword with a question mark?

Getting the class of an object.

Consider;

- - -

class Dance
def foo
puts "foo is executed"
42
end
end

class Boogy < Dance
def bar
puts (foo.class)
end
end

b = Boogy.new

b.foo # prints "foo is executed" ... expected.

b.bar # prints "foo is executed\nFixnum" ...

Accessing a local variable through a symbol

Let's say I have

def y
a=42
x = some_kernel_function(:a) # I'd like x to be 42
end

Is there a way to get x to be 42?

Metaprograming question about initialize

How many times have we seen this:

class X
attr_accessor :arg1, :arg2, :arg3, :arg4

def initialize(arg1, arg2, arg3, arg4)
@arg1, @arg2, @arg3, @arg4 = arg1, arg2, arg3, arg4
end
end

Wouldn't it be nice if we (ok, I) could instead write

def initialize(arg1, arg2, arg3, arg4)
initargs
end

and have initargs create the attr_accessor as well as the assignments.

I know I can do this in 1.9.2

class X
def initialize(arg1)
self.class.send(:attr_accessor, :arg1)
@arg1 = arg1
end
end

So is it possible in Ruby to introspect on the _names_ of arguments passed in to a fun

How are closures implemented?

I'm one of those people who needs to see/understand a typical implementation of something before I can grok how it works.

How are closures implemented? How does the closure know about its environment?

Difference between return and "not return"

Why is this syntactically valid

def x
return 1, 2
end

but this isn't

def y
1, 2
end

Difference between reurn and "not return"

Why is this syntactically value

def x
return 1, 2
end

but this isn't

def y
1, 2
end

uniq with count; better way?

a = [4,5,6,4,5,6,6,7]

result = Hash.new(0)
a.each { |x| result[x] += 1 }

p result

The result I am getting
{4=>2, 5=>2, 6=>3, 7=>1}
is what I want.

Is there a better way; perhaps using uniq?

Is there a difference between these two kinds of raise

Is there a semantic difference bewteen
raise MySpecialError, "My Message"
and
raise MySpecialError.new("My Message")

rescue Exception => ex

I am trying to grok
rescue MySpecialError => ex

Does the
=>
have anything to do with hashes or is this syntax reserved for rescue clauses?

Language deisng question and stinrgs and object id's

a = "string"
b = "string"

causes three objects with different object id's to be created.

irb(main):001:0> a = "string"
=> "string"
irb(main):002:0> b = "string"
=> "string"
irb(main):003:0> "string".object_id
=> 19087248
irb(main):004:0> a.object_id
=> 21660552
irb(main):005:0> b.object_id
=> 22419972

Yet
a = "string"
b = a
only causes two objects to be created.

irb(main):001:0> a = "string"
=> "string"
irb(main):002:0> b = a
=> "string"
irb(main):003:0> "string".object_id
=> 22106544
irb(main):004:0> a.object_id
=> 22650984
irb(main):005:0> b.object_id
=> 22650984

Yes, I

File size of web-based flv. Reading some bytes from a web-based file.

This is such a noobie question.

I have a file, http:// ... /One-minute-commercial-027.flv (I can't enter the name because the email gets rejected with a 5.7.1 as spam, apparently.

I want to do two simple things:

1) I want to get the file size. Please note that File.size() does not seem to work for me for a web-based file but does work for a local file.

C:\Users\Ralph>irb
irb(main):001:0> File.size('c:/RailsInstaller/Sites/ultradedup002/app/views/usage/VideoTutorials.html.haml')
=> 32406
irb(main):002:0> File.size('http:// ...

File size of web-based flv. Reading some bytes from a web-based file.

This is such a noobie question.

I have a file, http:// ... /One-minute-commercial-027.flv (I can't enter the name because the email gets rejected with a 5.7.1 as spam, apparently.

I want to do two simple things:

1) I want to get the file size. Please note that File.size() does not seem to work for me for a web-based file but does work for a local file.

C:\Users\Ralph>irb
irb(main):001:0> File.size('c:/RailsInstaller/Sites/ultradedup002/app/views/usage/VideoTutorials.html.haml')
=> 32406
irb(main):002:0> File.size('http:// ...

Is this message rejected with a 5.7.1

I am trying to post a message but am getting kicked out with a 5.7.1. This is a test with a more-or-less empty message

Ralph Shnevlar

Trying to find what added an empty array to an array of strings

At C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/i18n_railtie.rb:53 I have

(rdb:1) pp I18n.load_path
["C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/activesupport-3.1.1/lib/active_support/locale/en.yml",
"C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/activemodel-3.1.1/lib/active_model/locale/en.yml",
"C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/locale/en.yml",
"C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/actionpack-3.1.1/lib/action_view/locale/en.yml",
[]]

As you can see I

rdb: Where'd 'continue' go?

I'm using rdb to debug a Rails application.

'help' lists all the commands and continue has disappeared.

a) How can I tell what version of rdb I'm running?
2) What happened to 'continue'?

ruby debugger & displaying backslashes in pathname

As I step through code, the Ruby debugger displays the file:line with forward slashes in the pathname.

Is there a switch that will turn the forward slashes to backslashes so I can conveniently open the files in a Windows environment?

Class instance method

Consider this irb session

C:\InstantRails-2.0-win\rails_apps>irb
irb(main):001:0> class M
irb(main):002:1> @w = "ralph"
irb(main):003:1>
irb(main):004:1* def M.v
irb(main):005:2> @w
irb(main):006:2> end
irb(main):007:1>
irb(main):008:1* end
=> nil
irb(main):009:0>
irb(main):010:0* puts M.v
ralph
=> nil
irb(main):011:0> puts M::v
ralph
=> nil

I think I understand M.v but what does M::v mean? Is there a semantic and/or philosophical difference between the two?

Where is my file?