# Casting issue

**URL:** <https://www.ruby-forum.com/t/casting-issue/88793>\
**Category:** Rails\
**Created:** [March 14, 2007, 1:23pm UTC](https://www.ruby-forum.com/t/casting-issue/88793 "2007-03-14T13:23:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chandra\_shekar\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/439d5e/32.png) [@chandra\_shekar\_G](https://www.ruby-forum.com/u/chandra_shekar_G)\
**Post date:** [March 14, 2007, 1:23pm UTC](https://www.ruby-forum.com/t/casting-issue/88793/1 "2007-03-14T13:23:53Z")

</div>

Hi

we are new to ruby on rails development and would like to have a  
solution for the below scenario.

we have created a complex object which contains two struct type objects  
one being an array type, when we try to return this complex object from  
a method ,we are getting a message like “dont know how to cast”.

can the members pls respond on the same,

thanks in advance

Rgds

chandra shekar G

---

<div class="post-metadata">

**Author:** ![chandra\_shekar\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/439d5e/32.png) [@chandra\_shekar\_G](https://www.ruby-forum.com/u/chandra_shekar_G)\
**Post date:** [March 14, 2007, 4:46pm UTC](https://www.ruby-forum.com/t/casting-issue/88793/2 "2007-03-14T16:46:16Z")

</div>

chandra shekar G wrote:

> we are new to ruby on rails development and would like to have a  
> solution for the below scenario.
> 
> we have created a complex object which contains two struct type objects  
> one being an array type, when we try to return this complex object from  
> a method ,we are getting a message like “dont know how to cast”.

Could you post an example of the code?

–  
Phlip  
[http://c2.com/cgi/wiki?ZeekLand](http://c2.com/cgi/wiki?ZeekLand) ← NOT a blog!!

---

<div class="post-metadata">

**Author:** ![chandra\_shekar\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/439d5e/32.png) [@chandra\_shekar\_G](https://www.ruby-forum.com/u/chandra_shekar_G)\
**Post date:** [March 15, 2007, 10:34am UTC](https://www.ruby-forum.com/t/casting-issue/88793/3 "2007-03-15T10:34:57Z")

</div>

# API class

class SampApi \< ActionWebService::API::Base  
api\_method :GetInfo, :expects =\> [:string,:string], :returns  
=\>[CompleteInfo]

end

# struct class TP

class TP \< ActionWebService::Struct  
member :Name, :string  
member :Address, :string  
end

# struct class DR

class DR \< ActionWebService::Struct  
member :Price, :string  
member :Tax, :string  
end

# Composite class

class CompleteInfo

def initialize  
@an\_array = []  
end

```
    class TP < ActionWebService::Struct

    end

    class DR < ActionWebService::Struct

    end

```

def assign\_to\_array (item)  
@an\_array \<\< item  
end  
end

# Controller class

class ContentController \< ApplicationController  
def GetInfo(param0,param1)  
p1 = @params[‘param0’]  
p2 = @params[‘param1’]

```
completeInfo = CompleteInfo.new

tP = CompleteInfo::TP.new()

dR1 = CompleteInfo::DR.new()

dR2 = CompleteInfo::DR.new()

dR3 = CompleteInfo::DR.new()

#TP
tP.Name = "user"
tP.Address = "IN"

#DR
dR1.Price = "10"
dR1.Tax = "1"

dR1.Price = "20"
dR1.Tax = "2"

dR3.Price = "30"
dR3.Tax = "3"

completeInfo.assign_to_array(dR1)
completeInfo.assign_to_array(dR2)
completeInfo.assign_to_array(dR3)

completeInfo

```

end

end

after execution of the above class the error message displayed is

“Don’t know how to cast CompleteInfo to CompleteInfo”
