{"id":15595128,"url":"https://github.com/simonneutert/ruby_dsl_example","last_synced_at":"2025-10-10T02:32:05.123Z","repository":{"id":82304148,"uuid":"88070854","full_name":"simonneutert/ruby_dsl_example","owner":"simonneutert","description":"Simple DSL Example in Ruby","archived":false,"fork":false,"pushed_at":"2022-06-16T19:59:34.000Z","size":4,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-06T10:02:35.499Z","etag":null,"topics":["dsl","example","metaprogramming","ruby"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simonneutert.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2017-04-12T16:00:17.000Z","updated_at":"2022-06-16T19:59:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"938aa694-ae99-4666-8c27-b86be55bf7a4","html_url":"https://github.com/simonneutert/ruby_dsl_example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/simonneutert/ruby_dsl_example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonneutert%2Fruby_dsl_example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonneutert%2Fruby_dsl_example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonneutert%2Fruby_dsl_example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonneutert%2Fruby_dsl_example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simonneutert","download_url":"https://codeload.github.com/simonneutert/ruby_dsl_example/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonneutert%2Fruby_dsl_example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279002542,"owners_count":26083400,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-10T02:00:06.843Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dsl","example","metaprogramming","ruby"],"created_at":"2024-10-03T00:43:07.248Z","updated_at":"2025-10-10T02:32:05.118Z","avatar_url":"https://github.com/simonneutert.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"check out [instance_eval](https://apidock.com/ruby/Object/instance_eval), because this is where the magic happens\n\n``` ruby\n# to not pollute the global namespace, wrap your DSL in a class\nmodule DslWrapper\n  class Post\n    def initialize(user)\n      @user = user\n      @post = []\n      @extras = {}\n    end\n\n    def text(str)\n      @post \u003c\u003c str\n      self\n    end\n\n    def hashtag(*strs)\n      strs.each do |str|\n        @post \u003c\u003c '#' + str\n      end\n      self\n    end\n\n    def link(str)\n      @post \u003c\u003c str\n      self\n    end\n\n    def post_on_facebook\n      fb_text = @post.join(' ')\n      begin\n        if fb_text.length \u003c= 440\n          puts \"#{@user}: #{fb_text}\"\n          puts @extras.inspect unless @extras.empty?\n        else\n          raise 'Your post is too long.'\n        end\n      rescue\n        puts \"I can't tweet this, your tweet is too long, sorry.\"\n      end\n    end\n\n    def method_missing(method, *args)\n      @extras[method] = args.join(', ')\n    end\n  end\nend\n# your exposed DSL method\ndef post_as(user, text = nil, \u0026block)\n  post = DslWrapper::Post.new(user)\n  post.text(text) if text\n  post.instance_eval(\u0026block) if block_given?\n  post.post_on_facebook\nend\n\n# granular\npost_as 'markz' do\n  text \"\"\"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n  Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit\n  in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\n  \"\"\"\n  hashtag 'ruby'\n  hashtag 'dsl'\n  link 'http://www.simon-neutert.de'\n  sexy 'objects'\nend\n\n# multiple hashtags\npost_as 'markz' do\n  text 'my dsl works'\n  hashtag 'ruby', 'dsl'\n  link 'http://www.simon-neutert.de'\n  sexy 'classy'\nend\n\n# chaining\npost_as 'markz' do\n  text(\"Mic check...\").hashtag(\"one\", \"two\").link('http://www.simon-neutert.de')\n  sexy 'bit'\nend\n\n# one liner\npost_as 'markz', 'Hi, I am Mark_Z!'\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonneutert%2Fruby_dsl_example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimonneutert%2Fruby_dsl_example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonneutert%2Fruby_dsl_example/lists"}