Last active
August 29, 2015 13:57
-
-
Save pbosetti/9599570 to your computer and use it in GitHub Desktop.
This script replicates a weird bug in mruby
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
#!/usr/bin/env mruby | |
# Dataset, Container and self.dataset are a minimal set of prerequisites that | |
# we extrapolated from our application, in order to replicate the bug | |
class Container | |
attr_accessor :key_converter, :match | |
attr_reader :hsh | |
def initialize | |
@hsh= Hash.new | |
end | |
def method_missing(name, *args, &block) | |
if name.to_s[-1] == '=' then | |
key = name.to_s.chop.to_sym | |
@hsh[key.to_sym] = args.first | |
else | |
return @hsh[name.to_sym] | |
end | |
rescue => e | |
puts "Got: #{name}(#{args})" | |
puts "content: #{@hsh}" | |
raise e | |
end | |
end | |
class Dataset | |
@@content = Container.new | |
def self.content; @@content; end | |
def self.content=(v); @@content = v; end | |
end | |
def self.dataset | |
yield Dataset.content | |
end | |
# Uncomment this dummy line and it breaks at key :initial_alpha in | |
# data.BoundaryConditions | |
# Comment it, and it works | |
a = '' | |
# Also, comment at least one line in data.Parameters and it runs | |
dataset do |data| | |
data.InfoLevel = 4 | |
data.Solver = { | |
:max_iter => 300, | |
:tolerance => 1e-9, | |
} | |
data.BoundaryConditions = { | |
:initial_n => 0, | |
:initial_alpha => 0, | |
:initial_u => 0, | |
:initial_v => 0, | |
:initial_z => 0, | |
:initial_phi => 0, | |
:initial_mu => 0, | |
:initial_Omega => 0, | |
:initial_omega_r => 0, | |
:initial_z_dot => 0, | |
:initial_phi_dot => 0, | |
:initial_mu_dot => 0, | |
:initial_as => 0, | |
:initial_delta => 0, | |
:final_n => 0, | |
:final_alpha => 0, | |
:final_u => 0, | |
:final_v => 0, | |
:final_z => 0, | |
:final_phi => 0, | |
:final_mu => 0, | |
:final_Omega => 0, | |
:final_omega_r => 0, | |
:final_z_dot => 0, | |
:final_phi_dot => 0, | |
:final_mu_dot => 0, | |
:final_as => 0, | |
:final_delta => 0 | |
} | |
data.Parameters = { | |
:C_dA => 0.50, | |
:I_r => 1, | |
:I_xx => 23.82, | |
:I_yy => 20.21, | |
:I_zz => 26.40, | |
:KL_f => 16.0, | |
:KL_r => 28.0, | |
:KS_r => 20.0, | |
:Pmax => 0.200e6, | |
:a => 0.4, | |
:b => 0.4, | |
:c_f => 0.5e3, | |
:c_r => 0.5e3, | |
:g => 9.81, | |
:h => 0.26, | |
:k_f => 0.10e5, | |
:k_r => 0.10e5, | |
:m => 165.0, | |
:r_r => 0, | |
:rho => 1.2, | |
:t_f => 1.055, | |
:t_r => 1.2, | |
:u0 => 0, | |
:wET => 1, | |
:wPL => 0, | |
:wn => 0, | |
:friction => 1, | |
:kappa_max => 0.5e-1, | |
:lambda_max => 0.1, | |
:min_speed => 5, | |
:Omega_f => 0, | |
:Omega_i => 0, | |
:alpha_f => 0, | |
:alpha_i => 0, | |
:as_f => 0, | |
:as_i => 0, | |
:delta_f => 0, | |
:delta_i => 0, | |
:mu_f => 0, | |
:mu_i => 0, | |
:n_f => 0, | |
:n_i => 0, | |
:phi_f => 0, | |
:phi_i => 0, | |
:u_f => 0, | |
:u_i => 0, | |
:v_f => 0, | |
:v_i => 0, | |
:z_dot_f => 0, | |
:z_dot_i => 0, | |
:z_f => 0, | |
:z_i => 0, | |
:mu_dot_f => 0, | |
:mu_dot_i => 0, | |
:omega_r_f => 0, | |
:omega_r_i => 0, | |
:phi_dot_f => 0, | |
:phi_dot_i => 0, | |
:posReg_h => 0.1e-1 | |
} | |
end | |
p Dataset.content |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment