One option is that you can inherit your class definition from Struct:
class Foo < Struct.new(:bar, :baz)
# << more stuff >>
end
f = Foo.new("bar value","baz value")
f.bar #=> "bar value"
f.baz #=> "baz value"
More Related Contents:
- Converting an array of numbers to characters ruby [closed]
- Why are exclamation marks used in Ruby methods?
- How to select unique elements
- What is “main” in Ruby?
- How to modify PATH for Homebrew?
- Difference between a class and a module
- How to implement an abstract class in Ruby
- Difference between various variables scopes in ruby
- Generating GUIDs in Ruby
- Mac user and getting WARNING: Nokogiri was built against LibXML version 2.7.8, but has dynamically loaded 2.7.3
- ERROR: While executing gem … (Gem::FilePermissionError)
- Interpolating a string into a regex
- Ruby: Installing rmagick on Ubuntu
- List comprehension in Ruby
- Ruby factorial function
- Better ruby markdown interpreter?
- How to understand the difference between class_eval() and instance_eval()?
- Read, edit, and write a text file line-wise using Ruby
- Ruby: filter array by regex?
- Overriding method by another defined in module
- Ruby gem for finding timezone of location [closed]
- What is the best way to split a string to get all the substrings by Ruby?
- Insert digital signature into existing pdf file
- What will give me something like ruby readline with a default value?
- Is it possible to have class.property = x return something other than x?
- Functional code examples in ruby
- Ruby local variable is undefined
- Understanding Ruby and OS I/O buffering
- Rake “already initialized constant WFKV_” warning
- Read and write YAML files without destroying anchors and aliases?