Created
October 5, 2010 01:44
-
-
Save tommeier/610826 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Something | |
CONSTANT_VALUES = ["Hooray - I have substance!", "Something Else"] | |
def self.do_something | |
puts "Constant value = #{Something::CONSTANT_VALUES.inspect}" | |
puts "Method Value = #{self.apply_something(Something::CONSTANT_VALUES)}" | |
end | |
def self.apply_something(values) | |
value_changed = [*values] | |
value_changed.slice!(0,30).each do |value| | |
#Do any processing | |
end | |
values | |
end | |
end | |
-------------- | |
>> Something.do_something | |
Constant value = ["Hooray - I have substance!", "Something Else"] | |
Method Value = | |
=> nil | |
>> Something.do_something | |
Constant value = [] | |
Method Value = | |
=> nil | |
>> Something.do_something | |
Constant value = [] | |
Method Value = | |
=> nil | |
-------------- | |
Ruby changes constants :( - in this instance it is the .slice! doing the dirty deed, to correct this we still need a 'dup' even on passed constants: | |
class Something | |
CONSTANT_VALUES = ["Hooray - I have substance!", "Something Else"] | |
def self.do_something | |
puts "Constant value = #{Something::CONSTANT_VALUES.inspect}" | |
puts "Method Value = #{self.apply_something(Something::CONSTANT_VALUES)}" | |
end | |
def self.apply_something(values) | |
value_changed = [*values.dup] | |
value_changed.slice!(0,30).each do |value| | |
#Do any processing | |
end | |
values | |
end | |
end | |
--------------- | |
>> Something.do_something | |
Constant value = ["Hooray - I have substance!", "Something Else"] | |
Method Value = Hooray - I have substance!Something Else | |
=> nil | |
>> Something.do_something | |
Constant value = ["Hooray - I have substance!", "Something Else"] | |
Method Value = Hooray - I have substance!Something Else | |
=> nil | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment