# Few Questions on Ruby

**URL:** <https://www.ruby-forum.com/t/few-questions-on-ruby/156500>\
**Category:** Ruby\
**Created:** [December 29, 2008, 7:37am UTC](https://www.ruby-forum.com/t/few-questions-on-ruby/156500 "2008-12-29T07:37:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anilbhat21](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/77aa72/32.png) [@anilbhat21](https://www.ruby-forum.com/u/anilbhat21)\
**Post date:** [December 29, 2008, 7:37am UTC](https://www.ruby-forum.com/t/few-questions-on-ruby/156500/1 "2008-12-29T07:37:32Z")

</div>

Given this module definition:

```
module Greeting
  def say_hello
    puts "Hello, my name is #{self.name}"
  end
end

```

1.) How to implement a class Foo using the Greeting module so that the  
following code example generates the expected output. Do not implement a  
say\_hello method.  
foo = Foo.new(“Fred”)  
foo.say\_hello  
\>\> Hello, my name is Fred

2.) How to Implement a class Bar using the Greeting module so that the  
following code example generates the expected output. Do not implement a  
say\_hello method.

```
Bar.say_hello
>> Hello, my name is Bar

```

3.) Given this class:

```
class Example
  @name
end

How would you describe the @name variable? Assume you have access

```

to this source code but can’t change it. How would you add methods to  
the Example class to set and get the value of @name?  
4.) In a Rails application, if it takes a long time for a page to load.  
If there is an action that dynamically generates a large binary file and  
sends this to clients via send\_data. How is this related to the slow  
response time? What change can we make to avoid this?

---

<div class="post-metadata">

**Author:** ![anilbhat21](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/77aa72/32.png) [@anilbhat21](https://www.ruby-forum.com/u/anilbhat21)\
**Post date:** [December 29, 2008, 12:40pm UTC](https://www.ruby-forum.com/t/few-questions-on-ruby/156500/2 "2008-12-29T12:40:45Z")

</div>

On 29.12.2008 07:37, Anil B. wrote:

> Given this module definition:

…

This looks suspiciously like homework or interview questions. What is  
your motivation for posting this seemingly unrelated list of questions /  
tasks?

robert

---

<div class="post-metadata">

**Author:** ![anilbhat21](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/77aa72/32.png) [@anilbhat21](https://www.ruby-forum.com/u/anilbhat21)\
**Post date:** [December 29, 2008, 9:39am UTC](https://www.ruby-forum.com/t/few-questions-on-ruby/156500/3 "2008-12-29T09:39:47Z")

</div>

Hello:),

1. 

module Greeting  
def say\_hello  
puts “Hello, my name is #{self.name}”  
end  
end

class Foo  
attr\_accessor :name  
include Greeting

def initialize(name)  
@name = name  
end

end

1. 

class Bar  
extend Greeting  
end

1. 

class Example

attr\_accessor :name

end

1. Client waits until request finishes even if client doesn’t download  
any data. Implement a background service to generate large files,  
implement user notification service to notify user after file is  
generated and ready to use.

Marius Å½ilÄ—nas  
removed\_email\_address@domain.invalid

Anil B. wrote:

> Given this module definition:
> 
> ```
> module Greeting
> def say_hello
> puts "Hello, my name is #{self.name}"
> end
> end
> 
> ```
> 
> 1.) How to implement a class Foo using the Greeting module so that the  
> following code example generates the expected output. Do not implement a  
> say\_hello method.  
> foo = Foo.new(“Fred”)  
> foo.say\_hello  
> \>\> Hello, my name is Fred
> 
> 2.) How to Implement a class Bar using the Greeting module so that the  
> following code example generates the expected output. Do not implement a  
> say\_hello method.
> 
> ```
> Bar.say_hello
> >> Hello, my name is Bar
> 
> ```
> 
> 3.) Given this class:
> 
> ```
> class Example
> @name
> end
> 
> How would you describe the @name variable? Assume you have access
> 
> ```
> 
> to this source code but can’t change it. How would you add methods to  
> the Example class to set and get the value of @name?  
> 4.) In a Rails application, if it takes a long time for a page to load.  
> If there is an action that dynamically generates a large binary file and  
> sends this to clients via send\_data. How is this related to the slow  
> response time? What change can we make to avoid this?

---

<div class="post-metadata">

**Author:** ![anilbhat21](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/77aa72/32.png) [@anilbhat21](https://www.ruby-forum.com/u/anilbhat21)\
**Post date:** [December 29, 2008, 1:03pm UTC](https://www.ruby-forum.com/t/few-questions-on-ruby/156500/4 "2008-12-29T13:03:40Z")

</div>

On Mon, Dec 29, 2008 at 2:39 PM, Robert K.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> This looks suspiciously like homework or interview questions. What is  
> your motivation for posting this seemingly unrelated list of questions /  
> tasks?

I can has homework solutionz! 🙂

---

<div class="post-metadata">

**Author:** ![anilbhat21](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/77aa72/32.png) [@anilbhat21](https://www.ruby-forum.com/u/anilbhat21)\
**Post date:** [December 29, 2008, 5:36pm UTC](https://www.ruby-forum.com/t/few-questions-on-ruby/156500/5 "2008-12-29T17:36:38Z")

</div>

On Mon, Dec 29, 2008 at 2:39 AM, Marius Þilënas [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> attr\_accessor :name  
> extend Greeting  
> end

I like the fact you can extend single instances, too…

f = Foo.new  
f.extend MyModule

Todd
