[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Assignment without attr=

Greg Willits

11/20/2007 12:21:00 AM

Not even sure what to call this for the thread subject

I want to create a class which is a simple packed set of digits (as a
string) as the one and only attribute of the class. There will be
several methods to extract chunks from and format this string, but
there's only the one attribute.

For the life of me I can't figure out how to to populate the dang this
to start with, without have to go through an attribute. If it were a
normal multi-attribute object, I'm fine, but in light of there only
being one attribute, I'm trying to work with it a different way. Maybe
I'm just going about it all wrong to start with?

The essentials:

class PackedNumber
def initialize
@packedNumber
end

def methodX
...
end

def methodY
...
end
end

So, I'd want to work with it like this:
whatever = PackedNumber.new('12345')
Or
whatever = PackedNumber.new
whatever = '12345' # but I don't want whatever to be String

I'm trying to avoid the obvious, and maybe this is what is not possible
whatever.packedNumber = '12345'

I tried creating a method just for = but that didn't fly

def =(chars)
@packedNumber = chars
end

Feels pretty lame I can't see this, but there ya go.

-- gw
--
Posted via http://www.ruby-....

20 Answers

Tim Hunter

11/20/2007 12:29:00 AM

0

Greg Willits wrote:
> Not even sure what to call this for the thread subject
>
> I want to create a class which is a simple packed set of digits (as a
> string) as the one and only attribute of the class. There will be
> several methods to extract chunks from and format this string, but
> there's only the one attribute.
>
> For the life of me I can't figure out how to to populate the dang this
> to start with, without have to go through an attribute. If it were a
> normal multi-attribute object, I'm fine, but in light of there only
> being one attribute, I'm trying to work with it a different way. Maybe
> I'm just going about it all wrong to start with?
>
> The essentials:
>
> class PackedNumber
> def initialize
> @packedNumber
> end
>
> def methodX
> ...
> end
>
> def methodY
> ...
> end
> end
>
> So, I'd want to work with it like this:
> whatever = PackedNumber.new('12345')
> Or
> whatever = PackedNumber.new
> whatever = '12345' # but I don't want whatever to be String
>
> I'm trying to avoid the obvious, and maybe this is what is not possible
> whatever.packedNumber = '12345'
>
> I tried creating a method just for = but that didn't fly
>
> def =(chars)
> @packedNumber = chars
> end
>
> Feels pretty lame I can't see this, but there ya go.
>
> -- gw

maybe I'm missing something obvious here, but why not just take the
initial value as an argument to initialize?

class PackedNumber
def initialize(packed_number)
@packedNumber = packed_number
end
# other stuff
end

pn = PackedNumber.new('12345')


--
RMagick: http://rmagick.ruby...

Chris Shea

11/20/2007 12:31:00 AM

0

> So, I'd want to work with it like this:
> whatever = PackedNumber.new('12345')

If that's all you want, you can do this:

class PackedNumber
def initialize(string)
@packednumber = string
end
end

HTH,
Chris

Justin Collins

11/20/2007 12:37:00 AM

0

Greg Willits wrote:
> Not even sure what to call this for the thread subject
>
> I want to create a class which is a simple packed set of digits (as a
> string) as the one and only attribute of the class. There will be
> several methods to extract chunks from and format this string, but
> there's only the one attribute.
>
> For the life of me I can't figure out how to to populate the dang this
> to start with, without have to go through an attribute. If it were a
> normal multi-attribute object, I'm fine, but in light of there only
> being one attribute, I'm trying to work with it a different way. Maybe
> I'm just going about it all wrong to start with?
>
> The essentials:
>
> class PackedNumber
> def initialize
> @packedNumber
> end
>
> def methodX
> ...
> end
>
> def methodY
> ...
> end
> end
>
> So, I'd want to work with it like this:
> whatever = PackedNumber.new('12345')
>
def initialize(num = nil)
@packedNumber = num
end

> Or
> whatever = PackedNumber.new
> whatever = '12345' # but I don't want whatever to be String
>
>

I don't think you can do this.

> I'm trying to avoid the obvious, and maybe this is what is not possible
> whatever.packedNumber = '12345'
>
> I tried creating a method just for = but that didn't fly
>
> def =(chars)
> @packedNumber = chars
> end
>
>
But you could do

def set(chars)
@packedNumber = chars
end

whatever = PackedNumber.new

whatever.set '12345'


or if you want it even shorter, less 'method-call-like'

def [] num
@packedNumber = num
end

whatever['12345']

-Justin

Greg Willits

11/20/2007 1:00:00 AM

0

Justin Collins wrote:
> or if you want it even shorter, less 'method-call-like'
>
> def [] num
> @packedNumber = num
> end
>
> whatever['12345']

Yeah, either of those (.set or [ ]) will be fine.

Tim Hunter wrote:
>maybe I'm missing something obvious here, but why not just take the
>initial value as an argument to initialize?

I want to allow assignment at initialization as you say, and an
alternate method too.

I'm just experimenting/exploring what's possible.

Thanks guys.

-- gw

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

Sebastian Hungerecker

11/20/2007 10:49:00 AM

0

Greg Willits wrote:
> =C2=A0 =C2=A0whatever =3D PackedNumber.new('12345')
> Or
> =C2=A0 =C2=A0whatever =3D PackedNumber.new
> =C2=A0 =C2=A0whatever =3D '12345' =C2=A0# but I don't want whatever to be=
String

Given that there is no String#~ this would work:
class String
def ~
PackedNumber.new self
end
end

whatever =3D ~"12345"

That a "little" hackish thogh ;-)

HTH,
Sebastian
=2D-=20
NP: Milhaven - Lord Of Birds
Jabber: sepp2k@jabber.org
ICQ: 205544826

Wayne

10/31/2013 6:19:00 PM

0



"Bill Steele" wrote in message
news:ws21-983CBA.14020631102013@70-3-168-216.pools.spcsdns.net...

In article <b5b3df453a06be9b5e19bb31c59d333c@dizum.com>,
"Cheap Hawaii Birth Certificates" <treason@barackobama.com> wrote:

> In a speech at Boston's Faneuil Hall on Wednesday afternoon,
> President Barack Obama discarded his now-infamous broken
> promise: "If you like your health insurance, you can keep your
> health insurance." Instead, he offered a new promise: "You will
> be getting a better deal," the president told health insurance
> consumers.
>
> He blamed insurance companies, not Obamacare, for the canceled
> policies:
>
> Now, if you had one of these substandard plans before the
> Affordable Care Act became law, and you really like that plan,
> you were able to keep it. That's what I said when I was running
> for office. That was part of the promise we made. But ever since
> the law was passed, if insurers decided to downgrade or cancel
> the substandard plans, what we said under the law is that you
> have got to replace them with quality, comprehensive coverage
> because that, too, was a central premise of the Affordable Care
> Act from the very beginning...
>
> So if you're getting one of these letters [canceling your
> insurance policy], just shop around in the new marketplace.
> That's what it's for...
>
> For the fewer than 5% of Americans who buy insurance on your
> own, you will be getting a better deal. So anyone peddling the
> motion that insurers are canceling people's plan without
> mentioning that almost all the insurers are encouraging people
> to join better plans with the same carrier and stronger benefits
> and stronger protections, while others will be able to get
> better plans with new carriers through the marketplace, and then
> many will get new help to pay for these better plans and make
> them actually cheaper--if you leave that stuff out, you're being
> grossly misleading, to say the least.

# What's really happening is that the ACA is making insurers change the
# stuff in their policies that was screwing consumers, so they have to
# raise their rates to make up for the lost profits.

And that was the plan all along. The dems knew that their own constituents
as well as the repubs wouldn't go for a universal system. So they set up a
universal system, but allowed current insurance to remain.

THEN....provisions were added to invalidate your current insurance.

Nothing short of doubleplusungood.

Yoorghis

10/31/2013 6:25:00 PM

0

On Thu, 31 Oct 2013 14:02:06 -0400, Bill Steele <ws21@cornel.edu>
wrote:

>What's really happening is that the ACA is making insurers change the
>stuff in their policies that was screwing consumers, so they have to
>raise their rates to make up for the lost profits.

"Changing stuff" means actually providing REAL coverage

Yes, that does cost more

However, those with lower incomes do qualify for subsidies (comes out
of the $738 Billion saved from uncompensated HC reimbursement,
stopping CEO compensation, high admin costs, and over-inflated HC
equipment)


Yoorghis

10/31/2013 6:41:00 PM

0

On Thu, 31 Oct 2013 11:19:20 -0700, "Wayne" <mygarbagecan@verizon.net>
wrote:

>
>
>"Bill Steele" wrote in message
>news:ws21-983CBA.14020631102013@70-3-168-216.pools.spcsdns.net...
>
>In article <b5b3df453a06be9b5e19bb31c59d333c@dizum.com>,
>"Cheap Hawaii Birth Certificates" <treason@barackobama.com> wrote:
>
>> In a speech at Boston's Faneuil Hall on Wednesday afternoon,
>> President Barack Obama discarded his now-infamous broken
>> promise: "If you like your health insurance, you can keep your
>> health insurance." Instead, he offered a new promise: "You will
>> be getting a better deal," the president told health insurance
>> consumers.
>>
>> He blamed insurance companies, not Obamacare, for the canceled
>> policies:
>>
>> Now, if you had one of these substandard plans before the
>> Affordable Care Act became law, and you really like that plan,
>> you were able to keep it. That's what I said when I was running
>> for office. That was part of the promise we made. But ever since
>> the law was passed, if insurers decided to downgrade or cancel
>> the substandard plans, what we said under the law is that you
>> have got to replace them with quality, comprehensive coverage
>> because that, too, was a central premise of the Affordable Care
>> Act from the very beginning...
>>
>> So if you're getting one of these letters [canceling your
>> insurance policy], just shop around in the new marketplace.
>> That's what it's for...
>>
>> For the fewer than 5% of Americans who buy insurance on your
>> own, you will be getting a better deal. So anyone peddling the
>> motion that insurers are canceling people's plan without
>> mentioning that almost all the insurers are encouraging people
>> to join better plans with the same carrier and stronger benefits
>> and stronger protections, while others will be able to get
>> better plans with new carriers through the marketplace, and then
>> many will get new help to pay for these better plans and make
>> them actually cheaper--if you leave that stuff out, you're being
>> grossly misleading, to say the least.
>
># What's really happening is that the ACA is making insurers change the
># stuff in their policies that was screwing consumers, so they have to
># raise their rates to make up for the lost profits.
>
>And that was the plan all along. The dems knew that their own constituents
>as well as the repubs wouldn't go for a universal system. So they set up a
>universal system, but allowed current insurance to remain.
>
>THEN....provisions were added to invalidate your current insurance.
>
>Nothing short of doubleplusungood.

No, that's real good

Since the uncompensated HC that, by law, MUST be reimbursed to states
is horrendous and at the highest possible prices, and that even those
with those cheap--cheap policies would eventually have to use ER, lose
their assets etc, the savings we get from NOT having to pay for
mega-million CEO salaries of providers and Insurance companies, NOT
have to pay for exhorbitant equipment and supply costs; NOT have to
pay Shareholder dividends---the savings (10 yr projected) of $738
BILLION can provide the subsidization of those whose income deserves
it (and "Keep what they got")

See?

Wayne

10/31/2013 8:26:00 PM

0



wrote in message news:9p8579hi2p1qsk5n9d5hjhn4dpqjjrvsre@4ax.com...

On Thu, 31 Oct 2013 11:19:20 -0700, "Wayne" <mygarbagecan@verizon.net>
wrote:

>
>
>"Bill Steele" wrote in message
>news:ws21-983CBA.14020631102013@70-3-168-216.pools.spcsdns.net...
>
>In article <b5b3df453a06be9b5e19bb31c59d333c@dizum.com>,
>"Cheap Hawaii Birth Certificates" <treason@barackobama.com> wrote:
>
>> In a speech at Boston's Faneuil Hall on Wednesday afternoon,
>> President Barack Obama discarded his now-infamous broken
>> promise: "If you like your health insurance, you can keep your
>> health insurance." Instead, he offered a new promise: "You will
>> be getting a better deal," the president told health insurance
>> consumers.
>>
>> He blamed insurance companies, not Obamacare, for the canceled
>> policies:
>>
>> Now, if you had one of these substandard plans before the
>> Affordable Care Act became law, and you really like that plan,
>> you were able to keep it. That's what I said when I was running
>> for office. That was part of the promise we made. But ever since
>> the law was passed, if insurers decided to downgrade or cancel
>> the substandard plans, what we said under the law is that you
>> have got to replace them with quality, comprehensive coverage
>> because that, too, was a central premise of the Affordable Care
>> Act from the very beginning...
>>
>> So if you're getting one of these letters [canceling your
>> insurance policy], just shop around in the new marketplace.
>> That's what it's for...
>>
>> For the fewer than 5% of Americans who buy insurance on your
>> own, you will be getting a better deal. So anyone peddling the
>> motion that insurers are canceling people's plan without
>> mentioning that almost all the insurers are encouraging people
>> to join better plans with the same carrier and stronger benefits
>> and stronger protections, while others will be able to get
>> better plans with new carriers through the marketplace, and then
>> many will get new help to pay for these better plans and make
>> them actually cheaper--if you leave that stuff out, you're being
>> grossly misleading, to say the least.
>
># What's really happening is that the ACA is making insurers change the
># stuff in their policies that was screwing consumers, so they have to
># raise their rates to make up for the lost profits.
>
>And that was the plan all along. The dems knew that their own constituents
>as well as the repubs wouldn't go for a universal system. So they set up a
>universal system, but allowed current insurance to remain.
>
>THEN....provisions were added to invalidate your current insurance.
>
>Nothing short of doubleplusungood.

# No, that's real good

# Since the uncompensated HC that, by law, MUST be reimbursed to states
# is horrendous and at the highest possible prices, and that even those
# with those cheap--cheap policies would eventually have to use ER, lose
# their assets etc, the savings we get from NOT having to pay for
# mega-million CEO salaries of providers and Insurance companies, NOT
# have to pay for exhorbitant equipment and supply costs; NOT have to
# pay Shareholder dividends---the savings (10 yr projected) of $738
# BILLION can provide the subsidization of those whose income deserves
# it (and "Keep what they got")

# See?

Your $738 billion "savings" is total bullshit. That obsolete number is
coming unraveled.

It would have been much cheaper to just provide free care for those who
can't pay.
And who says that the buyers of cheap policies will end up costing money in
the ER?
Hell, I paid for health insurance for probably 20 years before I had
anything more serious than a yearly checkup.

Yoorghis

10/31/2013 9:28:00 PM

0

On Thu, 31 Oct 2013 13:25:37 -0700, "Wayne" <mygarbagecan@verizon.net>
wrote:

>
>
>wrote in message news:9p8579hi2p1qsk5n9d5hjhn4dpqjjrvsre@4ax.com...
>
>On Thu, 31 Oct 2013 11:19:20 -0700, "Wayne" <mygarbagecan@verizon.net>
>wrote:
>
>>
>>
>>"Bill Steele" wrote in message
>>news:ws21-983CBA.14020631102013@70-3-168-216.pools.spcsdns.net...
>>
>>In article <b5b3df453a06be9b5e19bb31c59d333c@dizum.com>,
>>"Cheap Hawaii Birth Certificates" <treason@barackobama.com> wrote:
>>
>>> In a speech at Boston's Faneuil Hall on Wednesday afternoon,
>>> President Barack Obama discarded his now-infamous broken
>>> promise: "If you like your health insurance, you can keep your
>>> health insurance." Instead, he offered a new promise: "You will
>>> be getting a better deal," the president told health insurance
>>> consumers.
>>>
>>> He blamed insurance companies, not Obamacare, for the canceled
>>> policies:
>>>
>>> Now, if you had one of these substandard plans before the
>>> Affordable Care Act became law, and you really like that plan,
>>> you were able to keep it. That's what I said when I was running
>>> for office. That was part of the promise we made. But ever since
>>> the law was passed, if insurers decided to downgrade or cancel
>>> the substandard plans, what we said under the law is that you
>>> have got to replace them with quality, comprehensive coverage
>>> because that, too, was a central premise of the Affordable Care
>>> Act from the very beginning...
>>>
>>> So if you're getting one of these letters [canceling your
>>> insurance policy], just shop around in the new marketplace.
>>> That's what it's for...
>>>
>>> For the fewer than 5% of Americans who buy insurance on your
>>> own, you will be getting a better deal. So anyone peddling the
>>> motion that insurers are canceling people's plan without
>>> mentioning that almost all the insurers are encouraging people
>>> to join better plans with the same carrier and stronger benefits
>>> and stronger protections, while others will be able to get
>>> better plans with new carriers through the marketplace, and then
>>> many will get new help to pay for these better plans and make
>>> them actually cheaper--if you leave that stuff out, you're being
>>> grossly misleading, to say the least.
>>
>># What's really happening is that the ACA is making insurers change the
>># stuff in their policies that was screwing consumers, so they have to
>># raise their rates to make up for the lost profits.
>>
>>And that was the plan all along. The dems knew that their own constituents
>>as well as the repubs wouldn't go for a universal system. So they set up a
>>universal system, but allowed current insurance to remain.
>>
>>THEN....provisions were added to invalidate your current insurance.
>>
>>Nothing short of doubleplusungood.
>
># No, that's real good
>
># Since the uncompensated HC that, by law, MUST be reimbursed to states
># is horrendous and at the highest possible prices, and that even those
># with those cheap--cheap policies would eventually have to use ER, lose
># their assets etc, the savings we get from NOT having to pay for
># mega-million CEO salaries of providers and Insurance companies, NOT
># have to pay for exhorbitant equipment and supply costs; NOT have to
># pay Shareholder dividends---the savings (10 yr projected) of $738
># BILLION can provide the subsidization of those whose income deserves
># it (and "Keep what they got")
>
># See?
>
>Your $738 billion "savings" is total bullshit. That obsolete number is
>coming unraveled.

By who---Faux snooze? Limpballs? Heritage? Or---WeeklyWorldNews?

>It would have been much cheaper to just provide free care for those who
>can't pay.

You moron---WE ARE NOW. That's why reform was required

Everyone that got "free care"---the provider charged the govt
(taxpayers) 5X what it would have cost if we provided a subsidized
pollicy. The provider was compensated for that care.

The reimbursement included CEO salaries, High care costs, Shareholders
dividends and every thing that goes with insurance billing (Ex. 18
cent Saline Drip bag---charged out at $81.00. A $200 wheel
chair---$1200. YOUR taxes paid that.

>And who says that the buyers of cheap policies will end up costing money in
>the ER?

Are you serioius?

Serious illness those policies are worthless. Deductible is
exhorbitant

Policy covers nothing and can be rescinded if health declines

>Hell, I paid for health insurance for probably 20 years before I had
>anything more serious than a yearly checkup.

If any given policy holder had to have more than a "Checkup"---even
you must be smart enough to figure out that a disaster was imminent