Leslie Viljoen wrote:
> Hello!
> 
> I am having a hard time using modules. It seems that to successfully
> use one, you
> need to know all sorts of obscure things about the environment that
> the module expects.
> 
> For example, I want to use Webby::Helpers::UrlHelper. This module
> refers to a @pages
> variable that I have to provide in the class that "include"s the
> module. That is not so
> hard, but I can only find that requirement via experimentation. If I
> provide the @pages
> variable in my class, I then find that the module refers to a method
> "h". I know rails
> has a helper method "h", but cannot otherwise find one, despite all my
> grep -ir "def h"  on the entire standard library and all gems (well,
> "rack" has such
> a method too, but Webby never uses rack AFAIK).
> 
> So is this how people normally use modules, or am I doing something 
> stupid?
> How is anyone supposed to know the possibly highly complex
> requirements of a module
> - or does it fall to documentation again?
> 
> There's a similar problem with calling *any* methods that take
> parameters in Ruby -
> how can you get a list of all the methods that will be applied to the
> object you passed
> in? Either the documentation says "pass in a string" and then you are 
> expected
> to pass in something that responds to ALL of string's methods, or the
> documentation
> must list every method applied, along with its signature. All the
> documentation I have
> seen uses option A: it mentions the class to pass in. Which renders
> duck-typing shot,
> unless I descend from that class perhaps?
> 
> BTW: where can I find the secret "h" method?
> 
> Les


This is ruby code:

puts 'hello'

--output:--
hello


This is also a ruby code:

#my_own_language.rb:
def puts(x)
  print "goodbye\n"
end


#my_program.rb
require 'my_own_language.rb

puts 'hello'

--output:--
goodbye



How would you respond to someone who constantly asks why puts in Ruby 
always outputs 'goodbye'?

-- 
Posted via http://www.ruby-forum.com/.