What can I .call? complete noob question, sorry

Hello

I am an absolute beginner in Ruby, having trouble understanding when to
use which objects - class, module, proc. I have tried googling the
available documentation but without success.

If I have

mystring = MyApp.call(someargs)

then what sort of thing should MyApp be? An instance of a class? A
module? A proc?

Thank you very much

Depends on what you want do exactly. What is MyApp, what is call, what
do you want it to do?

To simplify things, think of it like this:

  • Proc: A function
  • Module: A collection of functions; or a namespace.
  • Class: A datatype. Strings, Integers, Arrays etc. are datatypes – you
    can create your own datatypes.

D. D. wrote in post #1178938:

Hello

I am an absolute beginner in Ruby, having trouble understanding when to
use which objects - class, module, proc. I have tried googling the
available documentation but without success.

If I have

mystring = MyApp.call(someargs)

then what sort of thing should MyApp be? An instance of a class? A
module? A proc?

Thank you very much

class MyApp
def self.call(arg)
puts arg
end
end

MyApp.call(‘hello’)

–output:–
“hello”

I am an absolute beginner in Ruby, having trouble understanding when to
use which objects - class, module, proc

Use whatever will work. Try them one by one until you come up with
something that works. When you are learning computer programming, you
are learning a series of tricks. You may not know why a trick will be
useful, but as you get more experience, you will start being able to
match the tricks you learned to problems you are trying to solve.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs