ruby ruby中的C#属性生成器

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby ruby中的C#属性生成器相关的知识,希望对你有一定的参考价值。

vars = {
  "DoesNotBlockInput" => "bool",
  "Invisible" => "bool",
  "OntopDoober" => "bool",
  "OntopOfBuilding" => "bool",
  "CenterOfCollider" => "bool",
  "ShowDimmer" => "bool",
  "DoesNotSendClickMessage" => "bool",
  "HideOnClickMiss" => "bool",
  "DoesNotHideOnClick" => "bool",
  "LookAtTreatment" => "bool",
  "TargetName" => "string",
  "ArrowText" => "string",
  "Location" => "ArrowLocation?", 
  "TargetSet" => "Type", 
  "Scale" => "Vector2", 
  "CustomOffset" => "Vector3", 
  "TargetPos" => "Vector3?", 
  "PerspectiveCamera" => "Camera", 
  "Target" => "GameObject"
}

def gen_prop(access, class_name, var_name, type)
  if type == "bool"
    return access + " " + class_name + " " + var_name + " { get { _" + var_name + " = true; return this; } }\n"
  else
    var_camel = var_name[0].downcase
    var_camel.concat var_name[1..var_name.length - 1]
    return access + " " + class_name + " " + var_name + " (" + type + " " + var_camel + ") { _"+ var_name + " = " + var_camel + "; return this; }\n"
  end 
end

def gen_var(access, class_name, var_name, type)
  return access + " " + type + " _" + var_name + ";"
end

vars.each {|key, value|
  puts gen_prop("public", "ArrowConfig", key, value)
  puts gen_var("public", "ArrowConfig", key, value)
  puts "\n"
}

以上是关于ruby ruby中的C#属性生成器的主要内容,如果未能解决你的问题,请参考以下文章

Ruby 代码中的 C/C++?

Ruby中的属性访问

如何从 Ruby 中的数组返回属性值?

通过单击 Ruby on Rails 中的按钮生成表单

C# ?? Ruby 中的运算符?

ruby on rails f.select 具有自定义属性的选项