-
-
Save hololeap/30c501e46629c7529d81 to your computer and use it in GitHub Desktop.
This file contains 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
TypeError: no implicit conversion of Array into String | |
from (irb):19:in `new' | |
from (irb):19 | |
from /usr/bin/irb:11:in `<main>' |
This file contains 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 SubarrayStruct < Struct | |
# Takes an Array of variables that will be initialized as empty arrays, and a list of normal variables | |
def initialize(subarray_names, *variables) | |
# Turn sublist_names into an Array (if not already) and combine it with variables, send | |
# this new Array to Struct.new as a list of arguments | |
super *(variables + Array(subarray_names)) do | |
define_method :initialize do | |
# Initializes each variable in sublist_names with an empty array | |
Array(subarray_names).each { |s| send "#{s}=", [] } | |
end | |
end | |
end | |
end | |
Test = SubarrayStruct.new [:array_one, :array_two], :var_three, :var_four | |
Test.new |
This file contains 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
variables = [:var_three, :var_four] | |
subarray_names = [:array_one, :array_two] | |
Test = Struct.new *(variables + Array(subarray_names)) do | |
define_method :initialize do | |
Array(subarray_names).each { |s| send "#{s}=", [] } | |
end | |
end | |
Test.new |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment