| | 319 | |
|---|
| | 320 | # For checking respond_to? without searching the attributes (which is faster). |
|---|
| | 321 | alias_method :respond_to_without_attributes?, :respond_to? |
|---|
| | 322 | |
|---|
| | 323 | # A Person object with a name attribute can ask person.respond_to?("name"), person.respond_to?("name="), and |
|---|
| | 324 | # person.respond_to?("name?") which will all return true. |
|---|
| | 325 | def respond_to?(method, include_priv = false) |
|---|
| | 326 | method_name = method.to_s |
|---|
| | 327 | if attributes.nil? |
|---|
| | 328 | return super |
|---|
| | 329 | elsif attributes.has_key?(method_name) |
|---|
| | 330 | return true |
|---|
| | 331 | elsif ['?','='].include?(method_name.last) && attributes.has_key?(method_name.first(-1)) |
|---|
| | 332 | return true |
|---|
| | 333 | end |
|---|
| | 334 | # super must be called at the end of the method, because the inherited respond_to? |
|---|
| | 335 | # would return true for generated readers, even if the attribute wasn't present |
|---|
| | 336 | super |
|---|
| | 337 | end |
|---|
| | 338 | |
|---|